PHP & cPanel:当电子邮件通过管道传送到 PHP 并发生错误时,如何防止退回?
PHP & cPanel: How to prevent bounce when a email is piped into PHP and a error occurs?
通过 cPanel 电子邮件用户过滤,电子邮件已成功传输到 PHP 脚本,但 PHP 脚本有执行时间限制(以防止 DoS)。出现时限错误时,邮件被退回。
尽管产生弹跳的原因是 PHP 错误,但实际上无法修复该错误,这就是有时间限制的原因。
退回邮件的示例是:
This message was created automatically by mail delivery software.
A message that you sent could not be delivered to one or more of its
recipients. This is a permanent error. The following address(es)
failed:
pipe to |/usr/bin/php -q /home/foo/bar/script.php
generated by moo@beer.cl
local delivery failed
------ This is a copy of the message, including all the headers. ------
------ The body of the messa[...]
人们可能首先想到的是,执行时间限制错误正在打印一条消息(这会自动导致退回),但事实并非如此,因为设置了 ini_set('display_errors', false);
。没有打印任何内容的证据是上面引用的消息中缺少 "The following text was generated during the delivery attempt: ..."。
小测试:
#!/usr/bin/php -q
<?php
set_time_limit(1);
ini_set('display_errors', false);
$fh_stdin = fopen('php://stdin', 'rb');
while (true) rand();
?>
不确定这里是否有问题,但是邮件处理器退回了邮件,因为当 PHP 脚本因错误异常终止时,PHP 进程 returns a shell.
的非零值(在本例中为 255)
当通过管道将电子邮件发送到脚本的 MTA 根据其 return 值 > 0 发现失败时,它认为失败并退回邮件(可能包括退回中的任何脚本输出消息)。
如果您不能(或不想)更改这些管道进程的最长执行时间,一种解决方案是将消息排队等待其他脚本处理,您可以将处理分解为件或增加时限。
使用 register_shutdown_function()
and set_error_handler()
I was unable to override PHP's return value for a timeout using exit(0)
这样可能不会成为解决方法。
您应该可以使用 set_time_limit
增加时间,除非您的 PHP 在安全模式下 运行 阻止它这样做。但是如果进程真的很长 运行 最好将消息排队等待处理,而不是在消息传入时尝试处理消息,因为这可能会导致瓶颈或服务器过载。
通过 cPanel 电子邮件用户过滤,电子邮件已成功传输到 PHP 脚本,但 PHP 脚本有执行时间限制(以防止 DoS)。出现时限错误时,邮件被退回。
尽管产生弹跳的原因是 PHP 错误,但实际上无法修复该错误,这就是有时间限制的原因。
退回邮件的示例是:
This message was created automatically by mail delivery software.
A message that you sent could not be delivered to one or more of its recipients. This is a permanent error. The following address(es) failed:
pipe to |/usr/bin/php -q /home/foo/bar/script.php
generated by moo@beer.cl
local delivery failed------ This is a copy of the message, including all the headers. ------
------ The body of the messa[...]
人们可能首先想到的是,执行时间限制错误正在打印一条消息(这会自动导致退回),但事实并非如此,因为设置了 ini_set('display_errors', false);
。没有打印任何内容的证据是上面引用的消息中缺少 "The following text was generated during the delivery attempt: ..."。
小测试:
#!/usr/bin/php -q
<?php
set_time_limit(1);
ini_set('display_errors', false);
$fh_stdin = fopen('php://stdin', 'rb');
while (true) rand();
?>
不确定这里是否有问题,但是邮件处理器退回了邮件,因为当 PHP 脚本因错误异常终止时,PHP 进程 returns a shell.
的非零值(在本例中为 255)当通过管道将电子邮件发送到脚本的 MTA 根据其 return 值 > 0 发现失败时,它认为失败并退回邮件(可能包括退回中的任何脚本输出消息)。
如果您不能(或不想)更改这些管道进程的最长执行时间,一种解决方案是将消息排队等待其他脚本处理,您可以将处理分解为件或增加时限。
使用 register_shutdown_function()
and set_error_handler()
I was unable to override PHP's return value for a timeout using exit(0)
这样可能不会成为解决方法。
您应该可以使用 set_time_limit
增加时间,除非您的 PHP 在安全模式下 运行 阻止它这样做。但是如果进程真的很长 运行 最好将消息排队等待处理,而不是在消息传入时尝试处理消息,因为这可能会导致瓶颈或服务器过载。