修改配置文件:
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. 查看压缩包:
解压:
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. 查看解压文件:
您可能感兴趣的文章:- 攻击者是如何将PHP Phar包伪装成图像以绕过文件类型检测的(推荐)
- PHP开发之归档格式phar文件概念与用法详解【创建,使用,解包还原提取】
- PHP中phar包的使用教程
- 解决PHP 7编译安装错误:cannot stat ‘phar.phar’: No such file or directory