My Apache error logs are showing the error "Premature end of script headers occurring" once in a while, and it seems that my site returns a 500 internal server error to the browser when it happens. The strange thing is, it will happen for a few minutes, then everything will return to normal.
2 Answers
The Apache Wiki has a good section on this error listing the most common cause: scripts which fail to properly output the HTTP header. It sounds like a script is occasionally crashing or timing out before it outputs and flushes the header which appears to you as the "Premature end of script headers"/500 error.
If possible, trying testing the script locally to make sure that it is correctly outputting the headers under all conditions.
- 3,384
- 1
- 17
- 16
-
Thanks. They are php pages that are only accessed in one way (by visiting them in the browser), but once in awhile the "Premature end of script headers" occurs. I guess it could be a script time out issue? Is there somewhere I can change the setting for that? – MF86 Mar 24 '11 at 18:44
If you're using mod_fcgid or fastcgi in general, you may have a mismatch between the number of children and/or requests apache is configured to use each fastcgi process for, and the number of children and/or requests php-cgi is using. Are you setting up the fastcgi environment variables in apache's configuration file, or are you using a wrapper script to set PHP_FCGI_CHILDREN (must be disabled with fcgid) and PHP_FCGI_MAX_REQUESTS?
If apache's configuration and PHP's environment variable settings don't match, then if PHP decides it's reached MAX_REQUESTS before apache decides it has, PHP will exit but apache will still think it's accepting requests.
You can read more about this and an example wrapper script and proper fcgid configuration here.
- 19,313
- 2
- 35
- 51