1. 安裝 xdebug
https://xdebug.org/docs/install
不同PHP版本需要安裝對應的xdebug,可以去這個鏈接https://xdebug.org/download/historical尋找適合你的PHP版本的Xdebug。
windows的安裝方式很簡單,直接將xdebug.dll文件拷貝到你的php擴展目錄下,然後配置php.ini
2. 配置xdebug的配置
修改php.ini文件,在文件底部添加下面代碼
Xdebug2.x版本的配置
[Xdebug]
;你的php ext路徑及xdebug文件
zend_extension=/php7.4.3nts/ext/php_xdebug.dll
xdeubg.default_enable=0
;%t:時間戳 %R:$_SERVER['REQUEST_URI'], %p:pid,更多參數可見:
;https://xdebug.org/docs/trace#trace_output_name
xdebug.trace_output_name=trace.%t.%R.%p
;以下都是trace手機的內容和格式配置,具體區別可見官方文檔
xdebug.show_mem_delta=1
xdebug.collect_params=4
xdebug.collect_return=1
xdebug.trace_format=1
;是否自動記錄trace日誌,我一般默認否
xdebug.auto_trace=0
xdebug.trace_output_dir=自定義自己的trace日誌目錄
Xdebug3.x版本的配置
[Xdebug]
;你的php ext路徑及xdebug文件
zend_extension=/php7.4.3nts/ext/php_xdebug.dll
xdebug.mode=develop,trace
;%t:時間戳 %R:$_SERVER['REQUEST_URI'], %p:pid,更多參數可見:
;https://xdebug.org/docs/trace#trace_output_name
xdebug.trace_output_name=trace.%t.%R.%p
;以下都是trace手機的內容和格式配置,具體區別可見官方文檔
xdebug.show_mem_delta=1
xdebug.collect_params=4
xdebug.collect_return=1
xdebug.trace_format=1
xdebug.output_dir=自定義自己的trace日誌目錄
3. 在需要追蹤的地方放置自己的追蹤開始方法和追蹤結束方法
xdebug_start_trace();
//自己的代碼
xdebug_stop_trace();
4. 下載閲讀軟件閲讀追蹤記錄
git倉庫裏的好幾個軟件都試過了,只有這個是最好用,效果最好。
Xdebug Trace View https://github.com/kuun/xdebug-trace-viewer