调试Web应用
编辑php.ini文件
xdebug.remote_enable=1
xdebug.remote_connect_back=1
xdebug.remote_port=9001
xdebug.idekey=PHPSTORM
- remote_enable=1 允许远程调试
- remote_connect_back=1 xdebug会回连发起HTTP请求的客户端机器,这个选项打开的时候remote_host配置项会被忽略,而remote_host配置项是用来显式指定远程调试的机器IP的
- remote_port=9001 指定远程调试机器的监听端口
- idekey=PHPSTORM 指定你在PHPSTORM中配置的IDE Key
其他常见的配置项:
- xdebug.remote_autostart 默认为0,设成1后xdebug每次都会尝试开启一个远程调试会话,即使你没有设置任何和开启远程调试相关的GET/POST/COOKIE变量
调试命令行脚本
export XDEBUG_CONFIG="idekey=PHPSTORM"
php -dxdebug.remote_enable=1 -dxdebug.remote_port=9001 -dxdebug.remote_host=172.16.120.160 -dxdebug.remote_connect_back=0 <your-script>
跟远程调试Web应用的配置差不多,只是一般你的php.ini会针对Web应用调试而配置,所以你需要在调试脚本的时候显式指定一些调试选项,特别是remote_host,因为脚本是在远程机器上执行的,不能像Web应用一样能够查询到发起请求的IP
相关链接
https://www.jetbrains.com/help/phpstorm/debugging-with-phpstorm-ultimate-guide.html
https://www.jetbrains.com/help/phpstorm/configuring-xdebug.html
https://xdebug.org/docs/all_settings
https://xdebug.org/docs/remote#starting
https://segmentfault.com/a/1190000011332021
https://segmentfault.com/a/1190000011387666
网友评论