FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Custom error-handling creates "500 internal server error"
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Custom error-handling creates "500 internal server error" [message #174400] Fri, 10 June 2011 08:18 Go to previous message
Luke is currently offline  Luke
Messages: 10
Registered: June 2011
Karma:
Junior Member
Hi there,

For AJAX-calls I'm buffering my output, check for errors and if an error occurred print a custom, json-formatted error message. If everything works as expected, the buffered output is printed. I don't send any headers in my script, but for some reason if an error occurs and my buffering's on, I get a "500 (Internal Server Error)" as response-header. If I switch off my custom error-handling an the same error is thrown, PHP responds with a "200 OK".. How can that be?

My code's this:

// Suppress normal error output
ini_set('display_errors', 0);

// buffer Output
ob_start();

// When the PHP-Script's ended check for errors an print buffered content or an error message
register_shutdown_function(function() {

$error = error_get_last();

if($error) {
ob_end_clean();
header('Content-type: application/json');
echo "{'some': 'json here'}";
}else{
ob_end_flush();
}

});
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Install GD on Windows
Next Topic: FDF extensions to PHP will not compile
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 20:07:04 GMT 2024

Total time taken to generate the page: 0.04988 seconds