I've got a CGI script that can take a very very long time to complete. Lengthy story short, it must process lots of data, run a lot of slow instructions, making some slow web queries, throughout which period it does not output anything, so when it's done, it finally prints its results in JSON format. It requires several minutes to operate, that is more than the Timeout directive occur my Apache web server's httpd.conf.

I'm not at liberty to alter that Timeout value globally for everybody around the entire server. I figured of maybe overriding that inside a per-directory basis utilizing a .htaccess file, however it appears like the Timeout directive isn't inshtaccess context, to ensure that can't be done. From things i understand, my script must constantly output data, and when it does not output data for that Timeout quantity of seconds, Apache surrenders.

I get the next error in Apache: (70007)The timeout specified has expired: ap_content_length_filter: apr_bucket_read() failed

So what can I actually do?

Well, to give the stupidly simple solution, why don't you simply make the script from time to time produce some output while it's working? You can just print "Processing..." every couple of steps, or if you wish to become more creative, get it print some status updates to point how it is doing. Or maybe you are concerned about becoming bored, print an interesting poem a line at any given time. (Type of jogs my memory of http://pages.cs.wisc.edu/~veeve/404.html)

If you won't want to do this, the following factor that involves my thoughts is by using asynchronous processing. Essentially, you will need to spawn another process in the CGI script, and perform the extended processing for the reason that separate process. The primary CGI script itself just results an easy HTML page that states the operation is working after which exits. That HTML page would also need to contain some logic for periodically checking to determine if the background process around the server has finished. Maybe it's a <meta http-equiv="refresh" ...> HTML element, or you might use AJAX.

A really practical approach would be to begin a background job and email the reaction to the customer. 1O-1 they'd prefer that instead of getting a browser window open all mid-day.

Totally accept David. I'd only include that web request running for minutes might be very irritating for clients. When the data can't be prepared in acceptable time I'd consider redecorating from the system. Can you really collect and preprocess the information before demands come? Better calculations? Faster CGI code? Sometimes systems request for complete spinning and frequently it turns out to be much better than patching it.

I emerged having a solution.

I'd start outputting a dummy HTTP header, like Dummy: ..., and that i can put whatever data I would like as the need for that header, also it wouldn't modify the relaxation from the output. And So I would output a personality to that particular dummy value every minute approximately, stopping it from timing out. So when I'm ready, I'm able to print a line return and continue printing the relaxation of my (real) HTTP headers and also the content from the document.