[英]how to convert a php script into a phar file?
该项目的目标是将php脚本转换为.phar
我的项目由: 1个单独的index.php组成,该类将类调用到/ lib和/ database文件夹中
目标是要分发的文件尽可能少(理想情况下为2:index.php和asset.phar,其中将包括/ lib和/ database中的所有文件)甚至1(index.phar)
我尝试使用empir取得了任何成功:以前有人这样做过吗?
有教程可用吗?
使用Phar
类 。 例如,将其放在compress.php
:
$phar = new Phar('index.phar');
$phar->addFile('index.php');
$phar->buildFromDirectory('lib');
$phar->buildFromDirectory('database');
从命令行运行php compress.php
。 Voilà,您有一个Phar。
我使用以下脚本:
<?php
$phar = new \Phar(__DIR__ . '/index.phar');
$phar->startBuffering(); // For performance reasons. Ordinarily, every time a file within a Phar archive is created or modified in any way, the entire Phar archive will be recreated with the changes.
$phar->addFile('index.php');
$phar->addFile('composer.json');
$phar->addFile('composer.lock');
$phar->buildFromDirectory(__DIR__ . '/vendor');
$phar->stopBuffering();
运行以下命令以运行先前的脚本:
$ php -dphar.readonly=0 index.php
(默认情况下,PHP中不创建phar存档。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.