[英]How to make an executable phar?
我想通过执行foo.phar <params>
而不是php foo.phar <params>
来启动一个phar脚本作为可执行文件。
It's easy by modifying the default stub (adding the shebang corresponding to php). 通过修改默认存根(添加对应于php的shebang)很容易。
// 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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.