gpt4 book ai didi

php - 来自 PHP 中注册的关闭函数的 debug_backtrace()

转载 作者:IT王子 更新时间:2023-10-28 23:50:01 26 4
gpt4 key购买 nike

在修补 this question 的答案时,我发现 debug_backtrace() 不会跟踪超出注册到 register_shutdown_function() 的函数,当从其中调用时。

这在 this comment 中提到过对于 register_shutdown_function()在 PHP 文档中,说明:

You may get the idea to call debug_backtrace or debug_print_backtrace from inside a shutdown function, to trace where a fatal error occurred. Unfortunately, these functions will not work inside a shutdown function.

解释得更详细一些,评论 this answer状态:

Doesn't work. The shutdown function occurs after the stack has unwinded. There is no stack information to dump.

有什么方法可以避免这种情况,强制 PHP 保留堆栈跟踪直到进程完全终止,或者我们应该接受它作为 PHP 内部的给定吗?

最佳答案

这是一个非常昂贵的解决方案。我没用过register_tick_function()tick而且我不确定它是否按预期工作。

declare(ticks=1);

function tick_handler() {
global $backtrace;
$backtrace = debug_backtrace();
}
register_tick_function('tick_handler');



function shutdown() {
global $backtrace;
// do check if $backtrace contains a fatal error...
var_dump($backtrace);
}
register_shutdown_function('shutdown');

关于php - 来自 PHP 中注册的关闭函数的 debug_backtrace(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7241834/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com