该药业://流包装可在5.3.0之后所有的PHP版本。Phar代表PHP Archive。它用于分发PHP应用程序或库,并作为普通的PHP文件执行。phar://包装程序支持使用fopen() 打开文件以进行读/写,重命名和目录流操作opendir() 以及创建和删除目录。
Phar类允许打包包含在phar存档目录中的应用程序资源。要执行读取操作,请将此归档文件放在phar://包装器中
首先,确保将php.ini中的phar.readonly设置设置为0。然后,创建一个src文件夹,其中放置了应用程序的所有资源。创建index.php文件
<?php echo "phar application started"; ?>
使用Phar类的对象通过buildFromDirectory()方法在src文件夹中构建包含文件的phar存档。将index.php指定为setDefaultStub
<?php
//php.ini设置phar.readonly必须设置为0-
$pharFile = 'app.phar';
//清理
if (file_exists($pharFile)) {
   unlink($pharFile);
}
if (file_exists($pharFile . '.gz')) {
   unlink($pharFile . '.gz');
}
//创建法尔
$p = new Phar($pharFile);
//使用整个目录创建我们的库
$p->buildFromDirectory('src/');
//指向需要所有类的主文件
$p->setDefaultStub('index.php', '/index.php');
//加-将其压缩为gzip-
$p->compress(Phar::GZ);
echo "$pharFile successfully created";
?>从命令行运行以上脚本
php create-phar.php
这将在工作目录中创建app.phar。要运行phar存档,请使用以下命令
php app.phar
<?php
echo file_get_contents('phar://app.phar/index.php');
?>这将显示index.php文件的内容