PHP除錯使用Sublime與Xdebug

Step0)如果沒有此dll檔(c:\xampp\php\ext\php_xdebug.dll),先下載php_xdebug.dll

https://odan.github.io/2020/12/03/xampp-xdebug-setup-php8.html


Step1)編輯php.ini啟用xdebug,修改後重新啟動apache,xdebug的設定如下。

[XDebug]

zend_extension = "c:\xampp\php\ext\php_xdebug.dll"

xdebug.remote_autostart = 1 

xdebug.remote_enable = 1

xdebug.remote_handler = "dbgp"

xdebug.remote_host = "127.0.0.1"

xdebug.remote_log="c:\xampp\tmp\xdebug.txt"

xdebug.remote_port = 9000

xdebug.trace_output_dir = "c:\xampp\tmp"

; 3600 (1 hour), 36000 = 10h

xdebug.remote_cookie_expire_time = 36000

Step2)使用函式phpinfo,確定php是否啟用xdebug

Step3)在sublime安裝Xdebug Client套件。

點選「Preferences->Package Control」,點選「Install  Package」,搜尋套件「Xdebug Client」進行安裝。

Step4)點選「Project ->  Add Folder  to Project」加入php資料夾到專案,點選「Project-> Save Project As」另存為專案檔。

Step5)經由Step4轉換成專案(Project)後,點選「Project ->    Edit   Project」編輯專案設定檔,settings的xdebug的url,改成要除錯的php網頁的網址。

Step6)新增中斷點,點選要中斷的行數,點選右鍵選擇「Xdebug->Add/Remove Breakpoint」,新增中斷點。

新增中斷點後,第9行左側出現灰色圓點,表示中斷點。

Step7)開始除錯,點選「Xdebug -> Start Debugging(Launch Browser)」。

程式會停留在第9行,下方顯示變數值,可看出變數i為1。

Step8)執行下一行點選「Xdebug -> Step Over」。