fread 超时与“mod_fcgid:从管道读取超时”
我的应用程序尝试访问的 URL 出现超时问题。我正在尝试捕获此超时并使用以下代码解决此问题:
$timeout = 120;
if(false == $handle = @fsockopen($host, $port, $errno, $errstr, $timeout))
{
throw new Exception("Could not connect to url: ".$errstr);
}
$getRequest = "GET {$url} HTTP/1.0\r\n";
$getRequest .= "Host: {$urlParts['host']}\r\n";
$getRequest .= "Connection: close\r\n\r\n";
fwrite($handle, $getRequest);
$maxExecutionTime = ini_get('max_execution_time');
set_time_limit($timeout+10);
stream_set_timeout($handle, $timeout);
$head = fread($handle, 1024); // Read the first 1024 bytes
if($maxExecutionTime == 0) {
$maxExecutionTime = 30;
}
set_time_limit($maxExecutionTime);
$stream_metadata = stream_get_meta_data($handle);
if($stream_metadata['timed_out'] === true) {
throw new Exception("Connection timed out");
}
我用于超时的 URL 位于防火墙后面,因此我无法共享它,但它设计为 sleep() 5 分钟。当我尝试运行此代码时,执行停止于 $head = fread($handle, 1024); 90 秒后,我从服务器收到 500 错误“脚本提前结束”。当我在 apache 日志中的调试级别进行调查时,我看到:
[Fri Aug 26 11:10:45 2011] [warn] [client 192.168.10.202] mod_fcgid: read timeout from pipe
[Fri Aug 26 11:10:45 2011] [error] [client 192.168.10.202] Premature end of script headers: validateUrl.php
“validateUrl.php”是我访问此脚本的 url。我不确定将 FcgidIOTimeout 增加到更高的值是否安全,因为它将适用于我的所有页面。有什么想法/意见吗?
系统详细信息: PHP 版本 5.2.13 在 Windows NT 上运行 EPG-WEB 5.2 build 3790 阿帕奇:阿帕奇/2.2.19 (Win32) mod_fcgid/2.3.6
I have an issue with a URL my application is trying to access timing out. I am trying to catch this timeout and to solve this problem am using this code:
$timeout = 120;
if(false == $handle = @fsockopen($host, $port, $errno, $errstr, $timeout))
{
throw new Exception("Could not connect to url: ".$errstr);
}
$getRequest = "GET {$url} HTTP/1.0\r\n";
$getRequest .= "Host: {$urlParts['host']}\r\n";
$getRequest .= "Connection: close\r\n\r\n";
fwrite($handle, $getRequest);
$maxExecutionTime = ini_get('max_execution_time');
set_time_limit($timeout+10);
stream_set_timeout($handle, $timeout);
$head = fread($handle, 1024); // Read the first 1024 bytes
if($maxExecutionTime == 0) {
$maxExecutionTime = 30;
}
set_time_limit($maxExecutionTime);
$stream_metadata = stream_get_meta_data($handle);
if($stream_metadata['timed_out'] === true) {
throw new Exception("Connection timed out");
}
My URL I am using for the timeout is behind a firewall, so I can not share it, but it is designed to sleep() for 5 minutes. When I try to run this code, execution stops at $head = fread($handle, 1024); and after 90 seconds I get a 500 error from the server "Premature end of script". When I investigate at the debug level in the apache logs I see:
[Fri Aug 26 11:10:45 2011] [warn] [client 192.168.10.202] mod_fcgid: read timeout from pipe
[Fri Aug 26 11:10:45 2011] [error] [client 192.168.10.202] Premature end of script headers: validateUrl.php
with 'validateUrl.php' being the url I am accessing this script through. I'm not sure increasing FcgidIOTimeout to a higher value is safe, as it would apply to all of my pages. Any ideas/ comments?
System details:
PHP Version 5.2.13 running on Windows NT EPG-WEB 5.2 build 3790
Apache: Apache/2.2.19 (Win32) mod_fcgid/2.3.6
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试在 httpd.conf 中使用其中一些指令:
来源:http://httpd.apache。 org/mod_fcgid/mod/mod_fcgid.html
Try some of those directives in your httpd.conf:
source: http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html