Excuse me if this has been discussed before, but I would like to know
the stance on this issue, it's hard to search the buglist or mailing
archives on stuff like http, 500 and fatal.
Would it be hard to implement an ini setting for throwing a http 500
error on a fatal error? It's hard to make certain applications and have
proper error handling if there is no way to do anything on a fatal error..
It would be even grander if php could try to run a fall-back script when
something really bad happens, but just having that 500 on fatal errors
would be awesome ..
If this is not going to happen anytime soon, would you accept a patch?
Evert
Evert | Rooftop wrote:
Excuse me if this has been discussed before, but I would like to know
the stance on this issue, it's hard to search the buglist or mailing
archives on stuff like http, 500 and fatal.Would it be hard to implement an ini setting for throwing a http 500
error on a fatal error? It's hard to make certain applications and have
proper error handling if there is no way to do anything on a fatal error..It would be even grander if php could try to run a fall-back script when
something really bad happens, but just having that 500 on fatal errors
would be awesome ..If this is not going to happen anytime soon, would you accept a patch?
How would you implement it. Fatal errors can happen after output has
already been sent in which case it is too late to change the http
status. And if you haven't sent anything yet, as in you are using
output buffering, then it is rather trivial to do in user space. Simply
start you script by setting the status to 500 and change it to 200 when
you know you have good output to send. That way if a fatal error
happens, the 500 will be sent.
-Rasmus
Thats a smart idea.. I like that
As for letting PHP do the 500, I tend to use output buffering everywhere
(i think most people do, supposed to be faster too) so I'm used to
setting header()
's wherever I need them..
Besides, in most of my script the business logic gets executed first,
and this is where most errors can happen.. only after the presentation
is done.
So the solution would be, if fatal error is triggered, and
headers_sent()
is false then set the error to 500..
Is this possible?
Evert
Rasmus Lerdorf wrote:
Evert | Rooftop wrote:
Excuse me if this has been discussed before, but I would like to know
the stance on this issue, it's hard to search the buglist or mailing
archives on stuff like http, 500 and fatal.Would it be hard to implement an ini setting for throwing a http 500
error on a fatal error? It's hard to make certain applications and
have proper error handling if there is no way to do anything on a
fatal error..It would be even grander if php could try to run a fall-back script
when something really bad happens, but just having that 500 on fatal
errors would be awesome ..If this is not going to happen anytime soon, would you accept a patch?
How would you implement it. Fatal errors can happen after output has
already been sent in which case it is too late to change the http
status. And if you haven't sent anything yet, as in you are using
output buffering, then it is rather trivial to do in user space.
Simply start you script by setting the status to 500 and change it to
200 when you know you have good output to send. That way if a fatal
error happens, the 500 will be sent.-Rasmus
Evert | Rooftop wrote:
Thats a smart idea.. I like that
As for letting PHP do the 500, I tend to use output buffering everywhere
(i think most people do, supposed to be faster too) so I'm used to
settingheader()
's wherever I need them..
You think wrong. There are very good reasons not to use output buffering.
Besides, in most of my script the business logic gets executed first,
and this is where most errors can happen.. only after the presentation
is done.So the solution would be, if fatal error is triggered, and
headers_sent()
is false then set the error to 500..
This produces inconsistent behavior. I would not be in favor of it.
I suggest you do as Rasmus suggested. Use register_shutdown_function()
perhaps to have a function to change the status code before output is
sent in your specific environment.
--
Brian Moon
http://dealnews.com/
It's good to be cheap =)
Brian Moon wrote:
Evert | Rooftop wrote:
Thats a smart idea.. I like that
As for letting PHP do the 500, I tend to use output buffering
everywhere (i think most people do, supposed to be faster too) so I'm
used to settingheader()
's wherever I need them..You think wrong. There are very good reasons not to use output
buffering.
calm down :S
Besides, in most of my script the business logic gets executed first,
and this is where most errors can happen.. only after the
presentation is done.So the solution would be, if fatal error is triggered, and
headers_sent()
is false then set the error to 500..This produces inconsistent behavior. I would not be in favor of it.
I suggest you do as Rasmus suggested. Use
register_shutdown_function()
perhaps to have a function to change the
status code before output is sent in your specific environment.
Yea I do like that idea, didn't think of that approach.
As for inconsistent behaviour.. It's not a huge deal, and the situation
can easily described in the documentation. But yea, this is also why I
proposed an ini setting.
Rasmus' solution solves my problem though. Thanks a lot!
Evert