You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Gregory Nicholls <gn...@level8.com> on 2000/07/11 20:02:24 UTC

question on mod-cgi

 Hiya,
    First an apology. I'm fairly sure this isn't the best place to post
this however I _think_ it has some relationship to how mod-cgi does it's
stuff so I hope I'll be excused.
    I'm trying to get a CGI script to process a request, send the
response and then continue processing.
Now as far as I can tell, it looks like I can't send any additional
requests over this connection until the script finally terminates.
I'm testing this by having a script flush stdout after sending the
response headers and then issue a sleep(60) to simulate additional
processing. I'm using persistent connections because I need SSL
(although the problem occurs with an SSL connection as well).
    Can someone tell me if this behaviour is correct and if so, are
there any tricks I could use to seduce the server into accepting more
work over the same connection ?
    Thanks,
        Greg.


Re: question on mod-cgi

Posted by Tom Harrington <tp...@crosstor.com>.
Gregory Nicholls wrote:
> 
>  Hiya,
>     First an apology. I'm fairly sure this isn't the best place to post
> this however I _think_ it has some relationship to how mod-cgi does it's
> stuff so I hope I'll be excused.
>     I'm trying to get a CGI script to process a request, send the
> response and then continue processing.
> Now as far as I can tell, it looks like I can't send any additional
> requests over this connection until the script finally terminates.
> I'm testing this by having a script flush stdout after sending the
> response headers and then issue a sleep(60) to simulate additional
> processing. I'm using persistent connections because I need SSL
> (although the problem occurs with an SSL connection as well).
>     Can someone tell me if this behaviour is correct and if so, are
> there any tricks I could use to seduce the server into accepting more
> work over the same connection ?

This is correct.  CGI handling code will not timeout on reading
from the script until a server timeout occurs, which defaults (I
think) to 300 seconds.  Ifthe script's standard output and error
are still open, Apache will wait until timeout.

This suggests a trick to do what you want-- If your CGI script 
closes stdout and stderr, it should be able to continue processing
without holding up the server or the client.  Obviously you cannot
print to either of these after this point, but that probably won't
be a problem.

You'll probably also want to fork(), and do your continued
processing in the child process.  Closing stdout and stderr
will end the request, and cleanup of the request-specific
resource pool will try to kill off any outstanding child
processes (your CGI code in this case).  That'd end the
continued processing real fast.

The potential risks of all this are left as an exercise for
the reader.  Doing a fork() out of CGI code doesn't seem like a
very good idea, security-wise, althouth I can't nail down the
exact threat it might pose.

-- 
Tom Harrington
CrosStor Software, Inc.
tph@crosstor.com