本文介绍了如何制作可执行的Phar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想直接通过执行foo.phar <params>
而不是php foo.phar <params>
将phar脚本作为可执行文件启动.
I want to start a phar script as an executable, directly by doing foo.phar <params>
instead of php foo.phar <params>
.
推荐答案
通过修改默认存根(添加与php相对应的shebang)很容易.
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();
这篇关于如何制作可执行的Phar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!