5

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 ?

1
  • 1
    Thank you for bringing Zephir to my attention. Commented Jul 20, 2018 at 12:00

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I'll try to add my own c functions to my zephir extension, seems like it's possible. thank you
I am pretty sure that what I proposed is not possible with zephir. You need to write a C extension.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.