php 中phar包的使用教程详解
程序员文章站
2023-11-05 13:01:16
修改配置文件:
vim /usr/local/php/etc/php.ini
[phar]
phar.readonly = off
压缩:...
修改配置文件:
vim /usr/local/php/etc/php.ini
[phar] phar.readonly = off
压缩:
a. 创建压缩脚本:
vim compress.php
<?php $exts = array( '*', ); $dir = __dir__; $file = 'test.phar'; $phar = new phar(__dir__ . '/' . $file, filesystemiterator::current_as_fileinfo | filesystemiterator::key_as_filename, $file); $phar->startbuffering(); foreach ($exts as $ext) { $phar->buildfromdirectory($dir, '/\.' . $ext . '$/'); } $phar->delete('build.php'); $phar->setstub($phar->createdefaultstub('index.php')); $phar->stopbuffering(); echo "打包完成".php_eol;
b. 执行压缩脚本:
php /home/lee/php/compress.php
c. 查看压缩包:
ll /home/lee/php
解压:
a. 创建解压脚本:
vim /home/lee/php/depress.php
<?php define('root',__dir__); $dir = root.'/extract'; if(!is_dir($dir)){ @mkdir($dir); } $phar = new phar(root.'/test.phar'); $phar->extractto($dir,null,true); echo "解压完成".php_eol;
b. 执行解压脚本:
php /home/lee/php/depress.php
c. 查看解压文件:
ll /home/lee/php/extract