Xdebug

2019-08-30

php.ini enable xdebug

xampp里自带该插件,如果是其他环境请下载:https://xdebug.org/download.php

xampp .eg

[XDebug]
zend_extension = "E:\enviroment\xampp_5.6.33\php\ext\php_xdebug.dll"
xdebug.profiler_append = 0
xdebug.profiler_enable = 1
xdebug.profiler_enable_trigger = 0
xdebug.profiler_output_dir = "E:\enviroment\xampp_5.6.33\php\tmp"
xdebug.profiler_output_name = "cachegrind.out.%t-%s"
xdebug.remote_enable = on
xdebug.remote_handler = "dbgp"
xdebug.remote_host = "127.0.0.1"
xdebug.trace_output_dir = "E:\enviroment\xampp_5.6.33\php\tmp"
xdebug.idekey = PHPSTROM
xdebug.remote_mode = "req"
xdebug.remote_port = 9000

phpstrom enable xdebug

通过file->settings->Languages Frameworks->PHP找到Servers,Host对应远程主机URL, Debugger 选用 Xdebug ,如果是远程调试,一定得开启路径映射功能,否则无法调试,本地的路径不用选,在新建远程项目的时候就已经确定,Absolute path on the server 则是远程主机的 Web 路径。

点击电话图标,开启调试监听

客户端触发调试

让客户端触发调试,有多种方式

在URL后追加参数

?XDEBUG_SESSION_START=forxdebug

往cookie里追加参数

XDEBUG_SESSION=PHPSTORM

我们可以借助Xdebug helper插件

从Chrome插件商店里安装:

https://chrome.google.com/webstore/detail/xdebug-helper/eadndfjplgieldjbigjakmdgkmoaaaoc

然后点击插件小图标开启debug,该插件会自动往cookie里追加XDEBUG_SESSION

在postman里直接添加cookie参数

往postman里Headers里添加

cookie:XDEBUG_SESSION=PHPSTORM

调试时修改变量值

可以新建一个watch,创建对应的变量,并赋值。