Reputation: 729
Is there a way to catch method/function calls and return event with php like the xdebug trace?
I tried using the register_tick_function, but i'm not pretty sure this is the good approach.
I also tried to do my own php extension (using Zephir) but still the same problem.
Btw, I don't want to use xdebug extension. What is the best approach ?
Upvotes: 5
Views: 373
Reputation: 192
The approach is to write a PHP extension that hooks into zend_execute and zend_execute_internal.
See the following related lines in the tideways_xhprof profiler extension:
https://github.com/tideways/php-xhprof-extension/blob/master/tideways_xhprof.c#L15-L18
These first two lines declare global variables to store the old / original function pointers into. The second two lines are the declaration of the new functions that wrap the original ones.
https://github.com/tideways/php-xhprof-extension/blob/master/tideways_xhprof.c#L67-L71
Now in module init, we can keep the reference of the old pointers and overwrite the one the Zend engine uses with our own functions.
https://github.com/tideways/php-xhprof-extension/blob/master/tideways_xhprof.c#L164-L200
These lines are the new implementations of the hooks. They call the original ones.
Xdebug does this in a similar way, but the code is much more complex, because it has many different features hooking into the function cycle.
Upvotes: 2