PHP - 识别调用函数的时间

mar*_*lek 3 php debugging overriding nowdoc

我正在考虑如何找到任何函数的调用位置.问题是我需要找到PHP调用mail()函数的位置.一种方法是使用register_tick_function(),但我需要打开每个文件并检查每行上的内容.该项目非常庞大,在PHP中解析每个文件需要很长时间.还有其他方法吗?或选项如何覆盖mail()功能?

Pau*_*xon 6

要覆盖内置邮件功能,请查看override_function,它是Advanced PHP Debugger PECL扩展的一部分 - 然后您可以使用 debug_backtrace 来查找调用者详细信息...

//define code to override mail function (note I've used php5.3 nowdoc syntax to avoid 
//the need to escape the dollar symbols!!
$code=<<<'CODE'
    $trace=debug_backtrace();
    $caller=array_shift($trace);

    echo 'mail() called by '.$caller['function']
    if (isset($caller['class']))
        echo 'in '.$caller['class'];
CODE;

//install override
override_function('mail', '$to,$subject,$msg,$hdrs,$params', $code);
Run Code Online (Sandbox Code Playgroud)