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
Re: Custom error-handling creates "500 internal server error" [message #174402 is a reply to message #174400] Fri, 10 June 2011 09:24 Go to previous messageGo to previous message
Erwin Moller is currently offline  Erwin Moller
Messages: 228
Registered: September 2010
Karma:
Senior Member
On 6/10/2011 10:18 AM, Luke wrote:
> 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();
> }
>
> });

http://nl2.php.net/manual/en/function.register-shutdown-function.php

Read it. :-)

Hint: Look up 'function' explanation:


=============================================
The shutdown function to register.

The shutdown functions are called as the part of the request so that
it's possible to send the output from them. There is currently no way to
process the data with output buffering functions in the shutdown function.
=============================================

Regards,
Erwin Moller

--
"That which can be asserted without evidence, can be dismissed without
evidence."
-- Christopher Hitchens
[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: Tue Nov 26 06:29:16 GMT 2024

Total time taken to generate the page: 0.05237 seconds