How to make an executable phar?

荒凉一梦 提交于 2019-12-31 10:49:08

问题


I want to start a phar script as an executable, directly by doing foo.phar <params> instead of php foo.phar <params>.


回答1:


It's easy by modifying the default stub (adding the shebang corresponding to php).

// start buffering. Mandatory to modify stub.
$phar->startBuffering();

// Get the default stub. You can create your own if you have specific needs
$defaultStub = $phar->createDefaultStub('index.php');

// Adding files
$phar->buildFromDirectory(__DIR__, '/\.php$/');

// Create a custom stub to add the shebang
$stub = "#!/usr/bin/php \n".$defaultStub;

// Add the stub
$phar->setStub($stub);

$phar->stopBuffering();


来源:https://stackoverflow.com/questions/11082337/how-to-make-an-executable-phar

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!