|
Prev: Your Event T's
Next: How can i get the location of an exit()/die() from withinregister_shutdown_function()?
From: Mathijs van Veluw on 16 Jul 2008 03:23 Hello there, I have an shutdown function to catch fatal-errors etc.. Now when there is an exit() somewhere i get an empty message from get_last_error(). I want to know the location of this exit() or die(). Is there a way to get the file and line-number from where the exit/die originated? Thx in advance.
From: "Eric Butera" on 16 Jul 2008 09:15 On Wed, Jul 16, 2008 at 3:23 AM, Mathijs van Veluw <mathijs.van.veluw(a)smscity.com> wrote: > Hello there, > > I have an shutdown function to catch fatal-errors etc.. > Now when there is an exit() somewhere i get an empty message from > get_last_error(). > I want to know the location of this exit() or die(). > > Is there a way to get the file and line-number from where the exit/die > originated? > > Thx in advance. The way I handle this is by throwing exceptions in my code. So let's say that there is a db connection/query failure for whatever reason. Instead of using query() or die() which is not user friendly, I throw an exception which bubbles up. Once it hits the top then I can catch it, log it accordingly, and show the user a friendlier error page saying Oops! With an exception you get exactly what you want, a full-blown stack trace complete with paths, line numbers etc. You also get the ability to be graceful about what you show to the end user. ....but I have the feeling that you're already dealing with a situation in lots of existing code. Perhaps you could combine some suggestions in this thread and replace your die/exit statements with a custom function which logs a debug_backtrace() and then really dies, but gracefully of course. :) As an aside, if I were to see some jibberish about a query and line numbers when I click a link I'd leave that site. (And for the archives) It is a security vuln to show full file paths to an end user. If someone is tampering with your system we shouldn't give them any more information than they can already get.
From: "Eric Butera" on 16 Jul 2008 09:52 On Wed, Jul 16, 2008 at 9:41 AM, Mathijs van Veluw <mathijs.van.veluw(a)smscity.com> wrote: > Well i don't use 'OR die()' stuff. But exceptions. > > For some reason from within the register_shutdown_function() function i get > an empty error message. > This only occurs, as far as i know, when there is an exit somewhere. > > I want to trace where this comes from. > > But i think that this isn't possible, as i looked on the web and there arn't > any solutions. > > Thx for the help. Well if this is a very specific issue that you're trying to resolve perhaps you could try and figure out how the user triggered the error. You could just save the remote address and request uri, do some access log searching and re-produce the path the user took through your site. This has been a helpful technique for me several times. One of the main problems for me is that I know how to use the systems I build, so I wouldn't click on stuff in the weird order some users do.
From: "Eric Butera" on 16 Jul 2008 14:18
On Wed, Jul 16, 2008 at 1:53 PM, tedd <tedd.sperling(a)gmail.com> wrote: > At 9:15 AM -0400 7/16/08, Eric Butera wrote: >> >> As an aside, if I were to see some jibberish about a query and line >> numbers when I click a link I'd leave that site. (And for the >> archives) It is a security vuln to show full file paths to an end >> user. If someone is tampering with your system we shouldn't give them >> any more information than they can already get. > > It can certainly help you for debugging, but I agree, it's not for > production. > > tedd I register an error handler & a shutdown function on new features so that I can get error reports via email. I hate trying to sift thru logs and junk so I really need it in my face. Of course this is a performance hit as it actually has to send emails and parse errors, but after I haven't got any mails in a while I turn it off. |