本文環境:php版本:5.4.45 (phpstudy),Xdebug 2.4.1(phpstudy檔案夾中自帶),phpstorm 2021.3
目錄- PHP配置
- 瀏覽器配置(插件安裝)
- 使用PHPStrom配置
- 使用VSCode配置
- 斷點除錯
為啥是這么老的版本呢???
因為在改老專案,其它版本應該都是類似的,
PHP配置
要在php的組態檔中指定Xdebug的路徑,和它的一些配置,具體在php.ini檔案中,配置以下內容(路徑要對應修改):
[XDebug]
xdebug.profiler_output_dir="D:\phpStudy\tmp\xdebug"
xdebug.trace_output_dir="D:\phpStudy\tmp\xdebug"
zend_extension="D:\phpStudy\php\php-5.4.45\ext\php_xdebug.dll"
xdebug.profiler_enable=on
xdebug.auto_trace=on
xdebug.collect_params=on
xdebug.collect_return=on
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.idekey=PHPSTORM
瀏覽器配置(插件安裝)
- 需要安裝Xdebug helper插件,商店地址:https://chrome.google.com/webstore/detail/xdebug-helper/eadndfjplgieldjbigjakmdgkmoaaaoc
無法下載則可使用我上傳到網盤的:https://cloud.189.cn/t/6zyMnajyamaq (訪問碼:is3y)

-
安裝好后右鍵進入配置,也是設定idekey,就是php.ini對應的,

-
開啟除錯

使用PHPStrom配置
- 在設定中指定Xdebug的埠相關,就是上面php.ini中配置的:

- 這里要開啟對debug的監聽:

使用VSCode配置
開始是使用VScode開發的,找了挺多教程都斷點不了,而且公司電腦裝PHPStom要申請,然后在自己電腦上裝了PHPStorm下來,然后再看了下拓展的檔案,VScode也能斷點了,
其實主要就是之前的瀏覽器插件沒裝(看了挺多教程都沒提到??)
PHP Debug Adapter for Visual Studio Code(檔案):
https://github.com/xdebug/vscode-php-debug/blob/main/README.md
-
在完成了之前的php配置,和瀏覽器配置后,要在VSCode中斷點除錯PHP的話要裝一個插件
PHP Debug,

-
然后進行了除錯選單,點擊運行除錯,或者點運行邊上的小齒輪圖示,可以看到除錯運行配置的JSON,修改其埠號與php.ini中相同,保存后就可以進行除錯了,
點擊查看代碼
{
linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9000
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 0,
"runtimeArgs": [
"-dxdebug.start_with_request=yes"
],
"env": {
"XDEBUG_MODE": "debug,develop",
"XDEBUG_CONFIG": "client_port=${port}"
}
},
{
"name": "Launch Built-in web server",
"type": "php",
"request": "launch",
"runtimeArgs": [
"-dxdebug.mode=debug",
"-dxdebug.start_with_request=yes",
"-S",
"localhost:0"
],
"program": "",
"cwd": "${workspaceRoot}",
"port": 9000,
"serverReadyAction": {
"pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",
"uriFormat": "http://localhost:%s",
"action": "openExternally"
}
}
]
}
斷點除錯
到此一切準備就緒,打上斷點就可以在愉快的除錯了,
PHPSTORM:

VSCode:

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/519022.html
標籤:PHP
下一篇:淺談PHP設計模式的工廠模式
