簡單說下為什么要用debug斷點調試,很多人在用var_dump、echo、exit 等來斷點調試,當你需要知道多個參數變化及多處打印時,這樣就有點心有余而力不足。安裝debug就能很好的解決這些問題。
一,php安裝debug
1、官網下載地址 : https://xdebug.org/download ,如果分不清版本官網還提供了 custom installation instructions.功能方便順利引入,我這里就使用custom installation instructions
官網Install頁的installing on window
2、重復phpinfo()頁面的所有放入框內,點擊 Analyes my phpinfo() output
點擊指向
3、分析頁面下載xdebug
點擊指向下載
4、配置xdebug
[xdebug]
;xdebug3后 很多不在是xdebug.remot,而是xdebug.client_
;xdebug 監聽端口 不要和fastcgi端口沖突,默認端口 9000,
xdebug.remote_port=9100
;使用postMan需要傳遞的cookie參數
xdebug.idekey="PHPSTORM"
;遠程主機
xdebug.remote_host="127.0.0.1"
;開啟遠程調試
xdebug.remote_enable=1
;調試器協議
xdebug.remote_handler="dbgp"
;debug 擴展路徑
zend_extension="D:/server/php/ext/php_xdebug.dll"
;開啟自動跟蹤回溯 (默認關閉 off)
xdebug.auto_trace=1
;是否應收集傳遞給函數的參數:0沒有
;1元素的類型和數量
;2元素的類型和數量,以及完整信息的工具提示
;3完整變量內容
;4完整的變量內容和變量名稱。
;5PHP將變量內容序列化,沒有名稱。
xdebug.collect_params=1
;目錄中創建文件
;日志信息輸出目錄
xdebug.profiler_enable=1
xdebug.profiler_output_dir="D:/server/php/debug"
;當為1時跟蹤文件將被追加,而不是在后續請求中被覆蓋。
;文件的名稱
;跟蹤輸出文件目錄
xdebug.trace_options=1
xdebug.trace_output_name= trace。%c
xdebug.trace_output_dir="D:/server/php/debug"
5、phpinfo 能到xdebug表示安裝成功
xdebug
二、設置phpstorm的debug,
1、phpstorm 設置php環境,選擇phpstom菜單file->Settings->Languages & frameworks->php,設置php.exe文件
phpstorm 設置設置圖文
2、phpstorm 設置php debug端口,選擇phpstom菜單file->Settings->Languages & frameworks->php->Debug,設置debug port 為php 配置文件里加xdebug.remote_port要一至。
debug端口設置圖文
3、phpstorm 設置php Servers,選擇phpstom菜單file->Settings->Languages & frameworks->php->Servers,設置對應的參數。
phpstorm 設置php Servers
4、phpstorm 使用需要header 里傳入Cookie=XDEBUG_SESSION=PHPSTORM
image.png
5、運行測試
運行測試圖文