有什么方法可以知道 xdebug 是否正在调试当前执行?

Is there any way to know if xdebug is debuggin the current execution?

我如何知道 PHP 中是否存在调试会话?我想是时候... 有一个监听连接。或者当有条件可以工作时(f.e。cookie XDEBUG_SESSION_START 存在)

有一个名为 xdebug_is_debugger_active() 的函数,您可以使用它来检查当前是否附加了调试器。

此处引用所有 xdebug_ 函数:https://xdebug.org/docs/all_functions

您也可以先检查该函数是否存在,以防您的代码在没有加载 xdebug 的情况下运行。

if (function_exists("xdebug_is_debugger_active") && xdebug_is_debugger_active()) {
    var_dump("I'm being debugged!");
}