PHP Phar is similar to the packaged file jar in Java, which compresses a class of files in a folder.
Objective
First you need to modify the php.ini configuration will Phar ReadOnly shutdown, default is not write Phar Package, include is enabled by default.
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 PharThe parameter is the name of the compressed package. BUILDFROMDIRECTORY Specifies the compressed directory, and the second parameter can be used to make a regular extension of the compressed file.
Phar::GZRepresents the use of gzip to compress this file. BZ2 compression is also supported. Modify the parameters to be PHAR::BZ2 able.
The setsub is used to set boot loaded files. Lib_config.php is automatically loaded and executed by default.
After executing this code, a Swoole.phar file is generated.
Using Phar to compress packages
<?phpinclude ' Swoole.phar '; include ' swoole.phar/code/page.php ';
With Phar You can easily package your code and integrate it into your online machine.
Summarize