Apache 2.2的CGI Perl的超时,仍然超时即使有定期打印Apache、Perl、CGI

2023-09-10 21:40:59 作者:我一直在找一个人

我有一个是从客户方的JavaScript调用AJAX一个CGI code。然而,呼叫的结果是由客户端丢弃。

I have a cgi code that is being called by AJAX from clientside javascript. However, the result of the call is discarded by the client.

在后台此code发生:

On the backend this code occurs:

$|=1;
my $i = 0;
while (<$fh_echo>)
{
    #To prevent apache timing out the cgi script. 
    print "." if $i % 100 == 0;

    #Do stuff
    $i++;
}

尽管定期打印出来,这仍然超时:

Despite the periodic print out, this still times out:

[warn] [client 10.23.12.87] Timeout waiting for output from CGI script 
[error] [client 10.23.12.87] (70007)The timeout specified has expired: ap_content_length_filter: apr_bucket_read() failed

我的身影了JavaScript丢弃输出不应该有任何形式的Apache是​​否允许CGI脚本继续冲击的事实。如果是的话,那么这里发生了什么?

I figure the fact that javascript discards the output shouldn't have any form of impact on whether or not apache allows the cgi script to continue. If so, then what is happening here?

推荐答案

禁用超时CGI脚本是自找麻烦。鉴于调用的结果是由客户端丢弃,您应该改为,将孩子迅速完成工作和家长完成。

Disabling the timeout for CGI scripts is asking for trouble. Given that the result of the call is discarded by the client, you should instead fork, have the child complete the work and the parent finish quickly.

请参阅看通过CGI 一个漫长的过程作出解释。具体而言,

See Watching long processes through CGI for an explanation. Specifically,

而现在的乐趣的一部分。我们将叉开始在第31行这使得父进程告诉Apache我们正在做回应这一请求,同时让孩子走下车来进行长期跟踪路由。 &hellip;

And now the fun part. We're going to fork starting in line 31. This permits the parent process to tell Apache that we're done responding to this request, while letting the child go off to perform the long traceroute. …

孩子的推移,但它必须先关闭标准输出,否则Apache会觉得可能还是会有一些输出未来的浏览器,而不会响应浏览器或释放连接,直到这一切解决。

The child goes on, but it must first close STDOUT, because otherwise Apache will think there might still be some output coming for the browser, and won't respond to the browser or release the connection until this is all resolved.