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

Dre*_*rew 4 php mod-fcgid fread

我的应用程序尝试访问超时的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");
    }
Run Code Online (Sandbox Code Playgroud)

我用于超时的我的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
Run Code Online (Sandbox Code Playgroud)

'validateUrl.php'是我正在访问此脚本的URL.我不确定将FcgidIOTimeout增加到更高的值是否安全,因为它适用于我的所有页面.有什么想法/意见吗?

系统详细信息:在Windows NT上运行的PHP 5.2.13版EPG-WEB 5.2 build 3790 Apache:Apache/2.2.19(Win32)mod_fcgid/2.3.6

小智 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>
Run Code Online (Sandbox Code Playgroud)

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

  • 将FcgidIOTimeout和FcgidBusyTimeout设置为超过PHP中的max_execution_time非常方便.但是,您可能希望将*Interval时间保留为默认值,或者保留为相应值的倍数,或者相应值的超时可能几乎是您设置它的两倍(即实际Busy超时可能是BusyTimeout + BusyScanInterval). (2认同)