Solution:
http://php.net/register_tick_function
See also:
http://php.net/manual/en/control-structures.declare.php
"Warning: register_tick_function() should not be used with threaded
web server modules with PHP 5.2 or lower."
"The declare construct can also be used in the global scope, affecting
all code following it (however if the file with declare was included
then it does not affect the parent file)."
That mean you need to be careful and test before using it.
At the beginning of your module use following code:
declare(ticks = 1);
Within the hook_boot or hook_init register your tick function.
register_tick_function('my_debugger_tick');
If you need to execute some PHP code at the end:
register_shutdown_function('my_debugger_shutdown');
Register tick function has completely different scope, that mean you
can't use already defined global variables. See $GLOBALS to which
variables you have access.
Use $bt = debug_backtrace() to check where you are. $bt[2]['function']
should be always the function, which is currently executed. You have
access also which file (line) is executed, which arguments are passed
to the function, etc.
If you need to save and use some data from tick function, simply
return those data.
function my_debugger_tick($dump = FALSE) {
static $result = array();
$result[] = debug_backtrace(TRUE);
if ($dump) {
return array($result);
}
}