天天看點

phpstorm使用xdebug斷點調試

都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選項是空的,則點選右側三個點進行配置

phpstorm使用xdebug斷點調試
phpstorm使用xdebug斷點調試

選擇好php版本後,如果xdebug擴充安裝正确的話,會在右側顯示xdebug的版本資訊

3.phpstorm的Debug配置,Settings->PHP->Debug

這裡的端口要和php.ini中的一緻

phpstorm使用xdebug斷點調試

4.phpstorm的Debug配置,Settings->PHP->Debug->DBGp Proxy

IDE key 就是在php.ini中配置的idekey

phpstorm使用xdebug斷點調試

5.phpstorm的Servers配置,Settings->PHP->Servers

name随便寫,Host寫項目的域名,截圖中我的項目使用的是本地host代理域名,port即項目運作的端口

phpstorm使用xdebug斷點調試

6.點選如下圖按鈕添加配置

name随便寫,Server就選擇我們剛剛添加的Server

phpstorm使用xdebug斷點調試
phpstorm使用xdebug斷點調試

7.啟用斷點

phpstrom設定如下,然後在程式的左側打上斷點後,再次請求程式,就可以開始調試了

phpstorm使用xdebug斷點調試
phpstorm使用xdebug斷點調試