ARTICLE AD BOX
Nowadays it's no more a problem - since 5.3 PHP learned at last to send 503 on error, not 200
Err, it seems it was 5.2.4:
Changed error handler to send HTTP 500 instead of blank page on PHP errors.
You need to set display_errors = off to make it work
I have the exact behavior on my windows Apache 2.4 with PHP 5.4.5
6 Comments
Your update sounds great!! But it is still not working for me. I've tested with PHP 5.3.10-1ubuntu3.4. I used a simple syntax error page <? error for testing. display_errors is disabled. I still get a blank page and response code 200. I'm using the apache2 sapi. Do you know a php version / web server combination with that you can produce the 500 ?
2013-01-08T17:51:48.74Z+00:00
You can, of course, write your own error handler. However, not all PHP errors are catchable. For instance, a syntax error won't even allow your code to run, including your error handler.
To handle catchable errors, you can use the auto_append_file and auto_prepend_file directives to place your error handling code code.
Non-catchable errors are a different issue. If PHP runs as Fast CGI, it will automatically generate a 500 status code for you. However, you're probably running PHP through some other SAPI (such as Apache module). No idea about that, sorry. (I'll report back if I find something.)
3 Comments
Response headers are not sent until PHP echoes the first byte of response body. You can change headers (and the status code) in the mean time. Keeping that in mind, here is a solution:
Set your script to send a 500 response code at the beginning of script and 200 at the end. Here is an example:
header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error'); if (rand(0, 1) == 1) { die("Script terminated prematurely"); } header($_SERVER['SERVER_PROTOCOL'] . ' 200 OK'); echo "Success";Just ensure that 200 response code is set at only one location in your code.
Note: you can use http_response_code (PHP >= 5.4) instead of header.
2 Comments
Explore related questions
See similar questions with these tags.




