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
Create a phar compressed package
<?php $phar = new Phar('swoole.phar'); $phar->buildFromDirectory(__DIR__.'/../', '/\.php$/'); $phar->compressFiles(Phar::GZ); $phar->stopBuffering(); $phar->setStub($phar->createDefaultStub('lib_config.php'));
##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.
Use phar compression package
##
<?php include 'swoole.phar'; include 'swoole.phar/code/page.php';
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!