How to use phar package PHP

巴扎黑
Release: 2023-03-14 17:30:01
Original
1964 people have browsed it

The phar in php is similar to the packaging file jar in java, that is, compressing a type of file in a folder.

Preface

First you need to modify the php.ini configuration to turn off readonly for phar. By default, phar packages cannot be written, and include is turned on by default. of.


phar.readonly => On
Copy after login

Create a phar compressed package


<?php
$phar = new Phar(&#39;swoole.phar&#39;);
$phar->buildFromDirectory(__DIR__.&#39;/../&#39;, &#39;/\.php$/&#39;);
$phar->compressFiles(Phar::GZ);
$phar->stopBuffering();
$phar->setStub($phar->createDefaultStub(&#39;lib_config.php&#39;));
Copy after login
# The parameter of

##new Phar is the name of the compressed package. buildFromDirectory specifies the compressed directory, and the second parameter can specify the extension of the compressed file through regular rules.

Phar::GZ indicates using gzip to compress this file. Also supports bz2 compression. Just change the parameter to PHAR::BZ2.

setSub is used to set the file to start loading. lib_config.php is automatically loaded and executed by default.

After executing this code, a swoole.phar file is generated.

Use phar compression package

##

<?php
include &#39;swoole.phar&#39;;
include &#39;swoole.phar/code/page.php&#39;;
Copy after login

Using phar can easily package your code and integrate Deploy to online machines.

Summarize

The above is the detailed content of How to use phar package PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!