[英]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.