php - 如何为 PHP 脚本找到正确的 Hashbang 或 Shebang

标签 php shebang hashbang

我已经设置了forwarder在我的 cPanel 中,以便任何发送至 [email protected] 的电子邮件将由 PHP 脚本选取并处理。

#!/usr/bin/php -q
<?php

$fd = fopen("php://stdin", "r");
$body = '';
while( !feof($fd) ){
    $body .= fread($fd, 1024);
}
fclose($fd);

//----doing my tasks, for example:--
mail('<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fc8f99909abc9185bd92938894998eb893919d9592d29f9391" rel="noreferrer noopener nofollow">[email protected]</a>', 'Test Subject', $body);

?>

我必须使用各种类型的 cPanel 提供商为我的多个客户运行几乎相同的解决方案。我的问题是第一行名为 Hashbang or Shebang 。从网上我发现以下 shebangs 基于 PHP 版本是有效的:

For PHP 5.2.x the shebang would be "#!/usr/bin/php"
For PHP 5.3.x the shebang would be "#!/usr/bin/php53"
//My test server is running with PHP 5.5 at this moment and "#!/usr/bin/php" works fine.

同样,有人说,#!/usr/local/bin/php#!/usr/local/lib/php 等。

我的问题:有没有办法为不同的 cPanel 环境(如 phpinfo())正确/直接/轻松地找到正确的 hashbang或使用任何编码或任何配置文件?

最佳答案

为了使您的脚本可移植,请尝试使用它,

#!/usr/bin/env php

这只是在您的 $PATH 中搜索名为 php 的可执行文件。这在 95% 以上的情况下都有效。如果您发现它无法在某个系统上运行,那么只需手动查找 PHP 的安装位置并修改该脚本即可。

关于php - 如何为 PHP 脚本找到正确的 Hashbang 或 Shebang,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41719650/

相关文章:

php - 如何在数据库中解析和插入数据

php - 我如何通过 html 输入表单进行 foreach 并插入多行或基于选定日期字段的一行?

php - 如何知道字段是否为空?

导入模块(并选择正确的解释器)的 Python shebang 问题

javascript - 谷歌会索引 hashbang/escaped_fragment 内容的正确 URL

url - URL 约定中的新 `#!` 是什么?

php - 为什么回显变量时不断出现替换字符?

c - 在shell中运行C程序时将相对路径扩展为完整路径

bash - 哈希冒号 (# :) mean as first line of shell script?

asp.net-mvc - AngularJS $routeProvider 和 ASP.NET MVC 中的相对 URL