【发布时间】:2015-04-21 14:44:37
【问题描述】:
我有一个 PHP 脚本需要很长时间并建立许多数据库连接。
大约 5 分钟后,服务器向我发送错误 500,error_log 显示以下内容:
(104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server
(104)Connection reset by peer: mod_fcgid: ap_pass_brigade failed in handle_request_ipc function
我用谷歌搜索了这个,发现明显的答案是更改域的“fcgi-bin/php5.fcgi”文件中的“PHP_FCGI_MAX_REQUESTS”变量或 Apache 配置文件中的“FcgidMaxRequestsPerProcess”变量,但我可以不要做这些,因为服务器托管多个网站,所有网站都使用 FastCGI 运行。
我试图捕捉错误 500 并使用以下 PHP 代码重定向页面:
register_shutdown_function('rerun');
$rerun = isset($_GET['rerun']) ? true : false;
main($rerun);
function main ($rerun=false) {
// Lots and lots of stuff
}
function rerun() {
if (error_get_last() != NULL) {
header('Location: http://www.example.com/myscript.php?rerun');
}
}
但它也不起作用,我仍然以错误 500 结束。
有人知道如何解决这个问题吗? 通过在本地声明 FastCGI 变量(即仅适用于本网站),或者最好是通过正确捕获错误 500 并在它全部崩溃之前触发“重新运行”功能。
【问题讨论】:
标签: php error-handling fastcgi