views:

93

answers:

2

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 
[error] [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?

+1  A: 

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.

szbalint
Crap I totally forgot! Thanks, I'll see if this helps. I usually just put newline after my prints so it flushes the output.
Razor Storm
Just saw that $| was set to 1 in the beginning of my code. So that means the whole time buffer WAS turned off, and this is still occurring. So it must be something else hm.
Razor Storm
Is the apache side timeout turned off aswell?
szbalint
Shouldn't it still allow the cgi to continue despite apache configurations? I thought the timeouts are only for if the script prints out nothing.
Razor Storm
As far as I know the timeout applies regardless whether there is something returned or not, what should matter is the script finishing execution and if not, the request is timed out.Please take a look at the TimeOut httpd.conf setting.
szbalint
Timeout 120, so should I just put in a huge number?Timeout 987987987987? Or is there a hardcoded value (0 perhaps) that means infinite? http://httpd.apache.org/docs/2.0/mod/core.html#timeout Doesnt seem to specify.
Razor Storm
I'd try TimeOut 0 first to disable it.
szbalint
Timeout 0 causes apache to timeout scripts immediately, I guess I'll just have to put in an arbitrary large number then.
Razor Storm
+1  A: 
Sinan Ünür
It is a forked process.
Razor Storm
And, are you closing `STDOUT` in the child and exiting immediately in the parent?
Sinan Ünür
Oh! closing STDOUT seems to make it work now. I'll do some more testing, but so far I have yet to get any time out errors.
Razor Storm