Apache 2.2 CGI perl timeouts, still times out even with periodic prints
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.
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
[e开发者_开发知识库rror] [client 10.23.12.87] (70007)The timeout specified has expired: ap_content_length_filter: apr_bucket_read() failed
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?
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.
See Watching long processes through CGI for an explanation. Specifically,
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. …
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.
Perl buffers output, please make sure $|
is set to a non-zero value.
Apache will timeout the request unless you disable that functionality, whether there is something returned or not from the cgi side.
精彩评论