如何通过xdebug_start_profiling手动启动xdebug代码分析?
- 内容介绍
- 文章标签
- 相关推荐
本文共计870个文字,预计阅读时间需要4分钟。
使用Xdebug进行手动调试、性能分析时,必须配合以下命令:
为什么 xdebug_start_profiling() 没反应?
常见现象:代码里写了 xdebug_start_profiling(),但 /tmp/xdebug/ 下始终没生成 cachegrind.out.* 文件。根本原因不是函数没执行,而是 Xdebug 根本没进入 profiling 模式。
-
xdebug.mode必须显式包含profile(例如xdebug.mode=debug,profile或xdebug.mode=profile),仅写xdebug.mode=debug不够 - PHP CLI 和 Web SAPI(如 Apache/FPM)可能加载不同
php.ini:用phpinfo()页面确认xdebug.mode实际值,别只改了 CLI 的配置 - 函数调用位置必须在 profiling 可生效的上下文中——比如不能放在
register_shutdown_function()里,因为那时 Xdebug 已退出 profiling 状态
xdebug_start_profiling() 的参数影响输出文件名
该函数支持一个可选参数 $filename,用于指定输出文件路径(需绝对路径且 Web 进程有写权限)。
本文共计870个文字,预计阅读时间需要4分钟。
使用Xdebug进行手动调试、性能分析时,必须配合以下命令:
为什么 xdebug_start_profiling() 没反应?
常见现象:代码里写了 xdebug_start_profiling(),但 /tmp/xdebug/ 下始终没生成 cachegrind.out.* 文件。根本原因不是函数没执行,而是 Xdebug 根本没进入 profiling 模式。
-
xdebug.mode必须显式包含profile(例如xdebug.mode=debug,profile或xdebug.mode=profile),仅写xdebug.mode=debug不够 - PHP CLI 和 Web SAPI(如 Apache/FPM)可能加载不同
php.ini:用phpinfo()页面确认xdebug.mode实际值,别只改了 CLI 的配置 - 函数调用位置必须在 profiling 可生效的上下文中——比如不能放在
register_shutdown_function()里,因为那时 Xdebug 已退出 profiling 状态
xdebug_start_profiling() 的参数影响输出文件名
该函数支持一个可选参数 $filename,用于指定输出文件路径(需绝对路径且 Web 进程有写权限)。

