都1202年了,你调试php的时候还在使用print_r();die();吗?今天说一下php断点调试工具xdebug,无需google的xdebugHelper!无需在postman请求时加cookie!绝对方便好用!
相关环境:windows10,phpstudy,php7.3,phpstorm2021.1.1
一、环境配置
首先需要开启php环境的xdebug扩展,安装扩展的方法请自行百度,php.ini中的配置如下
说明:我使用的phpstudy,开启扩展后会自动在php.ini中自动添加xdebug的配置;
但是xdebug.idekey和xdebug.remote_autostart是我自己后面加上去的,xdebug.idekey等会需要配置在phpstorm中。
xdebug.remote_autostart即开启远程调试自动启动,允许你直接用phpstorm或浏览器访问某个方法时自动断点拦截,而不是点击IDE的爬虫图标才进行断点。
[Xdebug]
zend_extension=D:/phpstudy_pro/Extensions/php/php7.3.4nts/ext/php_xdebug.dll
xdebug.collect_params=1
xdebug.collect_return=1
xdebug.auto_trace=Off
xdebug.trace_output_dir=D:/phpstudy_pro/Extensions/php_log/php7.3.4nts.xdebug.trace
xdebug.profiler_enable=Off
xdebug.profiler_output_dir=D:/phpstudy_pro/Extensions/php_log/php7.3.4nts.xdebug.profiler
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9010
xdebug.remote_handler=dbgp
xdebug.idekey = PHPSTORM
xdebug.remote_autostart = 1
至此环境配置完毕,可以phpinfo()查看xdebug是否安装成功,下面开始phpstorm相关的配置
二 、phpstorm配置
1.首先配置phpstorm的php版本,Settings->PHP
如果CLI Interpreter选项是空的,则点击右侧三个点进行配置

选择好php版本后,如果xdebug扩展安装正确的话,会在右侧显示xdebug的版本信息
3.phpstorm的Debug配置,Settings->PHP->Debug
这里的端口要和php.ini中的一致
4.phpstorm的Debug配置,Settings->PHP->Debug->DBGp Proxy
IDE key 就是在php.ini中配置的idekey
5.phpstorm的Servers配置,Settings->PHP->Servers
name随便写,Host写项目的域名,截图中我的项目使用的是本地host代理域名,port即项目运行的端口
6.点击如下图按钮添加配置
name随便写,Server就选择我们刚刚添加的Server
7.启用断点
phpstrom设置如下,然后在程序的左侧打上断点后,再次请求程序,就可以开始调试了