我已经设置了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/