开发者

How to Avoid CGI Timeout?

I have a PHP process which the user runs in the browser, but tends to take a fairly long time - upwards of 5 minutes. We just switched to a new server, and when we try to run the script now, it consistently times out at 4 minutes exactly, sending to a 500 Internal Server Error page and outputting the following erro开发者_JAVA技巧rs in the error log:

Timeout waiting for output from CGI script

Premature end of script headers: cgi_wrapper

What's interesting is that the PHP process does seem to complete in the background. If we navigate away from the 500 Error page and wait a bit, the desired changes from the script do get made.

Is there any way to unhinge this CGI limit which seems to have been placed on us? I have read about FastCGI, but am not sure how to install this on our server (Apache, centOS, PHP 5.3).

Thanks for your help!


Probably the web server times out waiting for a response from the script. Actually with four minutes the server seems to be pretty patient. The default for FastCGI connections is 30 seconds.

It may help sending (and flush()ing) some data to the client while he is waiting. This tells both the web server and the browser that the request is still alive.

For example, if your script serves a HTML page at the end you may send a <!-- please wait... -> from time to time. It won't be visible to the user.

Anyway, any script that takes more than 10 seconds to complete is bad design. I suggest doing that work in the background in a separate process and have the client poll the completion status. Be aware that some browsers / proxies may time out the request no matter what you do on the server.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜