Preface
After PHP5.3, it supports Java-like jar package called phar. Used to package multiple PHP files into one file.
First, you need to modify the configuration to turn off the phar readonly. The default is that the phar package cannot be written, and include is enabled by default.
=> On
Create a phar compressed package
<?php $phar = new Phar(''); $phar->buildFromDirectory(__DIR__.'/../', '/\.php$/'); $phar->compressFiles(Phar::GZ); $phar->stopBuffering(); $phar->setStub($phar->createDefaultStub('lib_config.php'));
new Phar
The parameter of the compressed package is the name of the package. buildFromDirectory specifies the compressed directory, and the second parameter can be used to define the extension of the compressed file through regularity.
Phar::GZ
Indicates that gzip this file is used. BZ2 compression is also supported. Modify the parameters toPHAR::BZ2
Just do it.
setSub is used to set the file to start loading. By default, lib_config.php will be automatically loaded and executed.
After executing this code, a file is generated.
Use phar compression package
<?php include ''; include '/code/';
Using phar can easily package your code and integrate it to online machines.
Summarize
The above is the entire content of this article. I hope that the content of this article will be of certain help to everyone’s study or work. If you have any questions, you can leave a message to communicate. Thank you for your support.