Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

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.

share|improve this answer
    
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.

share|improve this answer
    
Thanks, but I'm not using fastcgi. –  MF86 Mar 24 '11 at 18:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.