简体   繁体   English

关于方法/函数调用事件的PHP

[英]PHP on method/function call event

Is there a way to catch method/function calls and return event with php like the xdebug trace? 有没有办法捕获方法/函数调用并返回事件与PHP像xdebug跟踪?

I tried using the register_tick_function, but i'm not pretty sure this is the good approach. 我尝试使用register_tick_function,但我不确定这是不错的方法。

I also tried to do my own php extension (using Zephir) but still the same problem. 我也尝试做自己的php扩展(使用Zephir),但仍然是同样的问题。

Btw, I don't want to use xdebug extension. 顺便说一句,我不想​​使用xdebug扩展。 What is the best approach ? 什么是最好的方法?

The approach is to write a PHP extension that hooks into zend_execute and zend_execute_internal. 方法是编写一个挂钩到zend_execute和zend_execute_internal的PHP扩展。

See the following related lines in the tideways_xhprof profiler extension: 请参阅tideways_xhprof profiler扩展中的以下相关行:

https://github.com/tideways/php-xhprof-extension/blob/master/tideways_xhprof.c#L15-L18 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 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. 现在在模块init中,我们可以保留旧指针的引用并覆盖Zend引擎与我们自己的函数一起使用的指针。

https://github.com/tideways/php-xhprof-extension/blob/master/tideways_xhprof.c#L164-L200 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. Xdebug以类似的方式执行此操作,但代码要复杂得多,因为它有许多不同的功能挂钩到函数循环中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM