mralston Posted February 18, 2011 Share Posted February 18, 2011 Is it possible to find out what line of code a PHP script was processing immediately before it is interrupted upon receiving a POSIX signal? A bit of background - I've got a PHP script which runs (from the command line) hundreds of thousands of times a day and usually it's just fine. Every so often (less than once a week) it gets into a muddle and freezes until I kill it. I've written a signal handler (using the posix_signal() function) into the script which catches SIGABRT signals. When it gets one, it dumps $GLOBALS to a file, cleanly releases the data its working on then exits. That gives me a nice 'get out of jail free' card, but I'd really like to identify where (and then why) it's freezing. I could insert loads of debugging code which sets some variable with what stage it's up to, but it's a fairly complicated script and I'd rather not. There's got to be a better way! __LINE__ and __FUNCTION__ unfortunately just point to my signal handler function. So, is there anyway that the function which is invoked by the SIGABRT signal can report what line of code the script was on at the time the SIGABRT was received? Or alternatively, is there a way to figure out what a running PHP script is doing if you know its PID? Maybe there's something in /proc/<PID> which might help me... Link to comment https://forums.phpfreaks.com/topic/228120-code-line-when-posix-signal-handler-invoked/ Share on other sites More sharing options...
mralston Posted February 18, 2011 Author Share Posted February 18, 2011 It seems that debug_backtrace() is my friend. Link to comment https://forums.phpfreaks.com/topic/228120-code-line-when-posix-signal-handler-invoked/#findComment-1176418 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.