我想直接通过 foo.phar <params>
将 phar 脚本作为可执行文件启动而不是 php foo.phar <params>
.
最佳答案
修改默认 stub (添加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();
关于php - 如何制作可执行的phar?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11082337/