我想将 phar 脚本作为可执行文件直接启动,foo.phar <params>
而不是php foo.phar <params>
.
问问题
7405 次
1 回答
17
通过修改默认存根(添加与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();
于 2012-06-18T11:57:44.127 回答