Prev: Looking for open source Learning Management System suggestions
Next: json_encode() behavior and the browser
From: Paul Freeman on 31 Aug 2010 04:49 When fatal error occurs is it possible to output also the backtrace in the error log? The simple error message with file line only is quite useless...
From: Simon J Welsh on 1 Sep 2010 05:33 I think you need a PHP extension to do this. XDebug works rather nicely for this. On 31/08/2010, at 8:49 PM, Paul Freeman wrote: > When fatal error occurs is it possible to output also the backtrace in the error log? The simple error message with file line > only is quite useless... > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > --- Simon Welsh Admin of http://simon.geek.nz/ Who said Microsoft never created a bug-free program? The blue screen never, ever crashes! http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e
From: Richard Quadling on 1 Sep 2010 06:30 On 31 August 2010 09:49, Paul Freeman <freeman3(a)centrum.cz> wrote: > When fatal error occurs is it possible to output also the backtrace in the error log? The simple error message with file line > only is quite useless... <?php namespace baz; set_error_handler( function($ErrNo, $ErrStr, $ErrFile, $ErrLine, $ErrContext){ echo 'An error occurred.', PHP_EOL; var_export(debug_backtrace(true)); // Allow PHP to continue executing. return false; }, -1 ); register_shutdown_function( function(){ echo 'We died a terrible death.'; var_export(debug_backtrace(true)); } ); function bar() { echo 'In ', __FUNCTION__, PHP_EOL; echo 1 / 0; // Divide by zero warning. foo(); } function foo() { echo 'In ', __FUNCTION__, PHP_EOL; $a = \SNAFU; // Fatal error } bar(); ?> outputs ... In baz\bar An error occurred. array ( 0 => array ( 'file' => 'Z:\\bad.php', 'line' => 24, 'function' => 'baz\\{closure}', 'args' => array ( 0 => 2, 1 => 'Division by zero', 2 => 'Z:\\bad.php', 3 => 24, 4 => array ( ), ), ), 1 => array ( 'file' => 'Z:\\bad.php', 'line' => 33, 'function' => 'baz\\bar', 'args' => array ( ), ), ) Warning: Division by zero in Z:\bad.php on line 24 In baz\foo Fatal error: Undefined constant 'SNAFU' in Z:\bad.php on line 30 We died a terrible death.array ( 0 => array ( 'function' => 'baz\\{closure}', 'args' => array ( ), ), ) So, it looks like extension or a core mod only. -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY
From: freeman3 on 1 Sep 2010 08:38 Thanks! I didn't notice the register_shutdown_function function. But it executes always I want to run it only to track fatal error. Also I can't get the backtrace properly:( I can't use 5.3 so I guess it works differently in 5.2 Richard Quadling wrote: > On 31 August 2010 09:49, Paul Freeman <freeman3(a)centrum.cz> wrote: >> When fatal error occurs is it possible to output also the backtrace in >> the error log? The simple error message with file line only is quite >> useless... > > <?php > namespace baz; > > set_error_handler( > function($ErrNo, $ErrStr, $ErrFile, $ErrLine, $ErrContext){ > echo 'An error occurred.', PHP_EOL; > var_export(debug_backtrace(true)); > > // Allow PHP to continue executing. > return false; > }, > -1 > ); > > register_shutdown_function( > function(){ > echo 'We died a terrible death.'; > var_export(debug_backtrace(true)); > } > ); > > function bar() { > echo 'In ', __FUNCTION__, PHP_EOL; > echo 1 / 0; // Divide by zero warning. > foo(); > } > > function foo() { > echo 'In ', __FUNCTION__, PHP_EOL; > $a = \SNAFU; // Fatal error > } > > bar(); > ?> > outputs ... > > In baz\bar > An error occurred. > array ( > 0 => > array ( > 'file' => 'Z:\\bad.php', > 'line' => 24, > 'function' => 'baz\\{closure}', > 'args' => > array ( > 0 => 2, > 1 => 'Division by zero', > 2 => 'Z:\\bad.php', > 3 => 24, > 4 => > array ( > ), > ), > ), > 1 => > array ( > 'file' => 'Z:\\bad.php', > 'line' => 33, > 'function' => 'baz\\bar', > 'args' => > array ( > ), > ), > ) > Warning: Division by zero in Z:\bad.php on line 24 > In baz\foo > > Fatal error: Undefined constant 'SNAFU' in Z:\bad.php on line 30 > We died a terrible death.array ( > 0 => > array ( > 'function' => 'baz\\{closure}', > 'args' => > array ( > ), > ), > ) > > So, it looks like extension or a core mod only. >
From: Richard Quadling on 1 Sep 2010 08:46
On 1 September 2010 13:38, <freeman3(a)centrum.cz> wrote: > Thanks! > I didn't notice the register_shutdown_function function. > But it executes always I want to run it only to track fatal error. Also I > can't get the backtrace properly:( I can't use 5.3 so I guess it works > differently in 5.2 > > Richard Quadling wrote: > >> On 31 August 2010 09:49, Paul Freeman <freeman3(a)centrum.cz> wrote: >>> When fatal error occurs is it possible to output also the backtrace in >>> the error log? The simple error message with file line only is quite >>> useless... >> >> <?php >> namespace baz; >> >> set_error_handler( >> Â Â function($ErrNo, $ErrStr, $ErrFile, $ErrLine, $ErrContext){ >> Â Â Â Â echo 'An error occurred.', PHP_EOL; >> Â Â Â Â var_export(debug_backtrace(true)); >> >> Â Â Â Â // Allow PHP to continue executing. >> Â Â Â Â return false; >> Â Â }, >> Â Â -1 >> ); >> >> register_shutdown_function( >> Â Â function(){ >> Â Â Â Â echo 'We died a terrible death.'; >> Â Â Â Â var_export(debug_backtrace(true)); >> Â Â } >> ); >> >> function bar() { >> Â Â echo 'In ', __FUNCTION__, PHP_EOL; >> Â Â echo 1 / 0; // Divide by zero warning. >> Â Â foo(); >> } >> >> function foo() { >> Â Â echo 'In ', __FUNCTION__, PHP_EOL; >> Â Â $a = \SNAFU; // Fatal error >> } >> >> bar(); >> ?> >> outputs ... >> >> In baz\bar >> An error occurred. >> array ( >> Â 0 => >> Â array ( >> Â Â 'file' => 'Z:\\bad.php', >> Â Â 'line' => 24, >> Â Â 'function' => 'baz\\{closure}', >> Â Â 'args' => >> Â Â array ( >> Â Â Â 0 => 2, >> Â Â Â 1 => 'Division by zero', >> Â Â Â 2 => 'Z:\\bad.php', >> Â Â Â 3 => 24, >> Â Â Â 4 => >> Â Â Â array ( >> Â Â Â ), >> Â Â ), >> Â ), >> Â 1 => >> Â array ( >> Â Â 'file' => 'Z:\\bad.php', >> Â Â 'line' => 33, >> Â Â 'function' => 'baz\\bar', >> Â Â 'args' => >> Â Â array ( >> Â Â ), >> Â ), >> ) >> Warning: Division by zero in Z:\bad.php on line 24 >> In baz\foo >> >> Fatal error: Undefined constant 'SNAFU' in Z:\bad.php on line 30 >> We died a terrible death.array ( >> Â 0 => >> Â array ( >> Â Â 'function' => 'baz\\{closure}', >> Â Â 'args' => >> Â Â array ( >> Â Â ), >> Â ), >> ) >> >> So, it looks like extension or a core mod only. >> > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > No. I think you've missed the point. Neither set_error_handler() or register_shutdown_function() report the fatal stack. This would need to be in an extension or a mod to the core code. Userland code can't access it. The stack trace shown in the shutdown function is just the shutdown function, not why there is a shutdown. -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY |