php - 如何制作可执行的phar?

标签 php shebang phar

我想直接通过 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/

相关文章:

c++ - 什么是 'shebang' 行?

ruby-on-rails - 如何检查将脚本/运行程序作为 shebang 的 ruby​​ 脚本的语法?

phpunit在phpstorm中运行问题,无法创建phar

php - 将 PHPUnit 测试打包为 PHAR 存档?

javascript - 如何在 php 变量中存储 javascript 函数值

php - Laravel 遍历查询结果,然后分页

php - 在 jquery 中调用 Codeigniter Controller 函数

php - 按字段排序不起作用,但没有错误