8

I have apache directives set up for custom error docs for 404, 403, etc, as well as 500. However, PHP, upon encountering a fatal error, displays a blank page instead of triggering the apache 500 response.

I don't need to display the error details or anything like that, as they are currently logged correctly in apache error_logs, so I don't think it has anything to do with error_reporting or display_errors, both of which are set correctly.

There are some similar questions here on SO, but haven't found an answer that does what I need. Basically, in the case of something like a syntax error, I want to see the apache 500 error page, NOT a blank page. This is not something that can be caught and handled in PHP, since syntax errors are uncatchable.

This appears to have been patched/fixed in php 5.2.4, as seen here: http://www.mail-archive.com/internals@lists.php.net/msg28557.html

However, we are using PHP 5.2.17, and an upgrade is not feasible at this time. Does anyone have any solutions / workarounds that might work to trigger 500 errors in apache for any PHP syntax/fatal error?

pnuts
  • 58,317
  • 11
  • 87
  • 139
Kevin Jhangiani
  • 1,597
  • 2
  • 13
  • 23
  • PHP 5.2.17 was released *after* PHP 5.2.4. Have you checked your php.ini? – Justin ᚅᚔᚈᚄᚒᚔ Jul 14 '11 at 06:40
  • Hmm no, tbh I have not. Do you happen to know what option in php.ini controls this? – Kevin Jhangiani Jul 14 '11 at 06:52
  • @RaúlFerràs I'm sorry no, I never found a solution for this. We have moved to new servers though, so I believe our PHP is now 5.3. I will have to check and see if the issue still occurs. – Kevin Jhangiani Oct 29 '12 at 10:40
  • 1
    @Kevin Jhangiani I've found that when an error happens in PHP, PHP is the responsible to manage it. So you will never be able to use the `ErrorDocument` directive as the error is "at PHP level". My blank pages were produced by php fatal errors, see this answer for more details: http://stackoverflow.com/a/2146171/111065. I think this solution also serves for syntax errors in PHP >= 5.3 – Pherrymason Oct 29 '12 at 11:47
  • "in the case of something like a syntax error" - get a decent ide, this shouldn't happen. – Ja͢ck Nov 28 '13 at 23:31

1 Answers1

1

Not sure if this works: register a shutdown handler and display the appropriate page. The shutdown handler should get called whenever a fatal error occurs. Make sure that you register the handler on top of your script.

towe75
  • 1,470
  • 10
  • 9
  • That will work for many situations, and is the solution I was most often able to find, however it will not work for syntax errors (and other uncatchable errors) since the code does not get executed at all. I'm looking for a way to make php behave similarly to perl, java, etc, and serve a proper apache 500 error, rather than a php triggered one. – Kevin Jhangiani Jul 14 '11 at 06:55