'mod_fcgid:从管道读取超时'的fread超时

时间:2011-08-26 02:32:59

标签: php 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增加到更高的值是安全的,因为它适用于我的页面的所有。有什么想法/意见吗?

系统详情: 运行在Windows NT EPG-WEB 5.2 build 3790上的PHP V5.2.13 Apache:Apache / 2.2.19(Win32)mod_fcgid / 2.3.6

1 个答案:

答案 0 :(得分:13)

在httpd.conf中尝试其中一些指令:

<IfModule fcgid_module>

    FcgidIOTimeout 1200
    FcgidConnectTimeout 1200
    FcgidBusyScanInterval 1200
    FcgidBusyTimeout 1200
    FcgidErrorScanInterval 1200
    FcgidIdleScanInterval 1200
    FcgidIdleTimeout 1200

    FcgidProcessLifeTime 3600
    FcgidZombieScanInterval 1200

</IfModule>

来源:http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html