The Java-like jar package, named Phar, is supported after PHP5.3. Used to package multiple PHP files into a single file.
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
<? New Phar ('swoole.phar'); $phar->buildfromdirectory (__ dir__. ' /.. /'/\.php$/'); $phar-Compressfiles (PHAR::GZ); $ Phar,stopbuffering (), $phar->setstub ($phar->createdefaultstub ('lib_ config.php'));
The parameter of the new Phar 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::gz means using gzip to compress this file. BZ2 compression is also supported. Modify the parameters to phar::bz2.
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
<? 'swoole.phar'swoole.phar/code/page.php' ;
With Phar You can easily package your code and integrate it into your online machine.
Use of Phar Packages in PHP