<p>Xdebug 3 收不到函数调用栈的根本原因是旧版 remote_ 参数失效且 xdebug.mode 未启用 trace;需设 xdebug.mode=debug,trace、xdebug.outputdir 可写,并替换 remote 为 client_* 等新参数,同时手动开启 collect_params 和 collect_return。</p>

Xdebug 3 升级后收不到函数调用栈,根本原因不是“功能坏了”,而是旧版 xdebug.remote_* 参数全部失效,且 xdebug.mode 未正确启用对应能力。
Xdebug 3 不再默认开启函数调用跟踪(即类似 xdebug.auto_trace 或 xdebug.collect_params 的行为),这些功能必须显式激活,并且要配合 xdebug.mode 的组合设置。
必须启用 debug 模式并补充 trace 功能
仅写 xdebug.mode=debug 只启动调试器(断点、堆栈、变量检查),不包含函数调用跟踪。要收集函数调用栈(如 xdebug_start_trace() 效果或自动 trace),需明确加入 trace:
xdebug.mode=debug,trace
同时指定输出目录(否则 trace 文件无法生成):
立即学习“PHP免费学习笔记(深入)”;
xdebug.output_dir="/path/to/your/xdebug-trace"
确保该目录存在、PHP 进程有写权限,且路径在 Windows 下使用正斜杠或双反斜杠(如 D:/tmp/xdebug)。
remote_* 参数已完全移除,必须替换为新参数
以下旧配置必须从 php.ini 中彻底删除,否则虽不报错,但会干扰逻辑、掩盖真实问题:
-
xdebug.remote_enable -
xdebug.remote_host -
xdebug.remote_port -
xdebug.remote_autostart -
xdebug.remote_connect_back xdebug.remote_handler
对应替换为:
-
xdebug.client_host=127.0.0.1(IDE 所在机器 IP,本地开发填127.0.0.1) -
xdebug.client_port=9003(Xdebug 3 默认端口,不是 9000) -
xdebug.start_with_request=trigger(按需触发,加?XDEBUG_SESSION_START=1)或yes(每次请求都连) -
xdebug.discover_client_host=true(替代remote_connect_back,用于动态 IP 场景)
⚠️ 注意:
xdebug.client_port若被防火墙拦截或被其他服务占用(如另一个 Xdebug 实例),会导致连接失败,表现为断点不生效、PhpStorm 显示“Waiting for connection”。
函数参数与返回值收集需单独开启
即使启用了 trace 模式,xdebug.collect_params 和 xdebug.collect_return 仍需手动设为 1 或 on,它们未被 xdebug.mode 统一管理:
xdebug.collect_params=1 xdebug.collect_return=1
这两项只在 xdebug.mode 包含 trace 时才起作用。若 mode 里没 trace,设了也无效。
验证是否生效的快捷方式
- 创建一个 PHP 文件,内容为:
<?php xdebug_info(); ?>
- 浏览器访问,查看页面中 "Mode" 行是否显示
debug,trace; - 查看 "Output Directory" 是否为你配置的路径,且状态为 “writable”;
- 检查 "Log" 区块是否有
TRACE START类提示(需xdebug.log_level=7临时开启日志辅助排查)。
不复杂但容易忽略



















