PHP - Catching session timeout issues

I've been working on a bug where an application is logging out unexpectedly.

To identify the piece of code that is destroying the session namespace I've been using the code snippet:

 $trace = ob_get_contents();
 file_put_contents(basename(__FILE__).'.out', var_export($trace,true).PHP_EOL.var_export($_SERVER, ,true).PHP_EOL);

What it does is dumps out the stack that called the function it is placed in.

You can add additional information like a timestamp or FILE_APPEND.

You may also want to use Zend's logging. The reason I don't use it is that every instruction adds overhead. Once this issue is resolved, I'll remove all the debug code. I hope.

Credit to the link. :)