前言:
特別注意:
一、
xdebug會(huì)提示不支持php7以下的版本(要自行選擇)
二、如果安裝了此插件,在安裝wordpress這種類型的開源平臺(tái)時(shí)會(huì)報(bào)錯(cuò),解決辦法參考 ==> 報(bào)錯(cuò)mysqli_init():屬性訪問不允許
1、下載對(duì)應(yīng)版本的xdebug
xdebug官網(wǎng)下載地址
你需要仔細(xì)分析和選擇要下載的對(duì)應(yīng)版本,否則無法調(diào)試。由于非常容易出錯(cuò),建議采用下面這種簡(jiǎn)單方法:
1.1xdebug網(wǎng)站提供一個(gè)自動(dòng)分析你系統(tǒng)對(duì)應(yīng)的xdebug版本的頁面,網(wǎng)址是 https://xdebug.org/wizard.php

圖1-1 xdebug網(wǎng)站提供的一個(gè)自動(dòng)分析系統(tǒng)對(duì)應(yīng)xdebug版本的頁面
1.2在頁面中需要粘貼進(jìn)去php版本信息,也就是phpinfo()函數(shù)的信息,如下圖:

圖1-2 phpinfo();函數(shù)返回的信息
1.3ctrl+A全選這個(gè)頁面的信息,然后粘貼到第一個(gè)圖片的頁面中。

圖1-3 向頁面中拷貝phpinfo()獲取的信息
1.4點(diǎn)擊 analyse my phpinfo() output按鈕
- 下載php_xdebug-2.7.2-7.2-vc15-nts.dll
- 將下載的文件移動(dòng)到
F:\phpStudy\PHPTutorial\php\php-7.2.1-nts\ext- 編輯
F:\phpStudy\PHPTutorial\php\php-7.2.1-nts\php.ini并添加該行
zend_extension = F:\phpStudy\PHPTutorial\php\php-7.2.1-nts\ext\php_xdebug-2.7.2-7.2-vc15-nts.dll重新啟動(dòng)Web服務(wù)器
圖1-4 找到你需要下載的xdebug版本
1.5到此為止,xdebug的下載和啟用就完成了,重新運(yùn)行 phpinfo.php 文件

image.png
2、修改php.ini配置
;指定xdebug庫(kù)文件的絕對(duì)路徑
zend_extension = F:\phpStudy\PHPTutorial\php\php-7.2.1-nts\ext\php_xdebug-2.7.2-7.2-vc15-nts.dll
;開啟遠(yuǎn)程調(diào)試,連接和監(jiān)聽主機(jī)和端口的調(diào)試客戶端
xdebug.remote_enable = On
;啟用代碼自動(dòng)跟蹤
xdebug.auto_trace=On
;允許收集傳遞給函數(shù)的參數(shù)變量
xdebug.collect_params=1
;允許收集函數(shù)調(diào)用的返回值
xdebug.collect_return=On
;客戶機(jī)ip
xdebug.remote_host="127.0.0.1"
;客戶機(jī)xdebug監(jiān)聽端口和調(diào)試協(xié)議
xdebug.remote_port=9000
;啟動(dòng)調(diào)試器協(xié)議dbgp
xdebug.remote_handler=dbgp
;指定DBGP調(diào)試器(IDE)處理程序區(qū)分大小寫
xdebug.idekey="PHPSTORM"
;啟用性能檢測(cè)分析
xdebug.profiler_enable = On
;關(guān)閉性能檢測(cè)分析觸發(fā)器
xdebug.profiler_enable_trigger = off
;指定性能分析文件的存放目錄
;xdebug.profiler_output_dir = "d:\tmp"
;指定性能分析文件的名稱
;xdebug.profiler_output_name = cachegrind.out.%t.%p
;指定堆棧跟蹤文件的存放目錄
;xdebug.trace_output_dir="d:\tmp"
;指定堆棧跟蹤文件的名稱
;xdebug.trace_output_name = trace.%c
栗子
情況一:只在IDE下調(diào)試
; 如果要開啟IDE下調(diào)試
zend_extension = "E:\phpstudy_pro\Extensions\php\php5.6.9nts\ext\php_xdebug-2.5.5-5.6-vc11-nts-x86_64.dll"
情況二:只在瀏覽器下調(diào)試基本操作
; 如果要開啟瀏覽器下調(diào)試 remote_enable默認(rèn)是關(guān)閉
xdebug.remote_enable=1
xdebug.remote_port=9000
xdebug.remote_host=127.0.0.1
調(diào)試
介紹下實(shí)際DEBUG過程中PHPSTORM面板的按鈕都是做什么用的。當(dāng)你啟動(dòng)監(jiān)聽后,你將會(huì)看到如下圖

根據(jù)上圖圖標(biāo)位置,以x,y坐標(biāo)的方式描述每個(gè)圖標(biāo)的功能。
| 圖標(biāo) | 位置 (x,y) | 功能 |
|---|---|---|
![]() |
0,0 | 重新執(zhí)行DEBUG (Rerun test.php) |
![]() |
0,1 | 跳轉(zhuǎn)到原調(diào)試文件 (Show execution point) |
![]() |
0,2 | 跳到下一行 (Step over) |
![]() |
0,3 | 執(zhí)行下一步 (Step info) |
![]() |
0,4 | 跳入庫(kù)、構(gòu)造函數(shù)等方法或類中 (Force Step Info) |
![]() |
0,5 | 執(zhí)行函數(shù)體或類方法,如果在最外層則結(jié)束本次調(diào)試 (Step out) |
![]() |
0,6 | 跳到當(dāng)前節(jié)點(diǎn)的下個(gè)斷點(diǎn) (Run to Cursor) |
![]() |
0,7 | 執(zhí)行修改變量或返回的結(jié)果用于二次調(diào)試(Evaluate arbitrary expression) |
![]() |
0,8 | 顯示值的地址 (Show Values Addresses) |
![]() |
0,9 | 是否顯示空的值 , 默認(rèn)是不顯示 |
![]() |
0,10 | 跳到下個(gè)斷點(diǎn) (Add method to skip list) |
![]() |
1,0 | 重新執(zhí)行DEBUG (Resume Program) |
![]() |
2,0 | 停止DEBUG(Step process) |
![]() |
3,0 | 查看和管理所有的斷點(diǎn) ( View and manage all breakpoints) |
![]() |
4,0 | 忽略所有斷點(diǎn) (Mute breakpoints) |















