如何使用Visual Studio Code除錯PHP CLI應用和Web應用

i042416發表於2019-07-24

在按照Jerry的公眾號文章 什麼?在SAP中國研究院裡還需要會PHP開發? 進行XDebug在本地的配置之後,如果想使用Visual Studio Code而不是Eclipse來除錯PHP應用,步驟也比較簡單。

啟動WAMP伺服器,確保xdebug.remote_autostart, xdebug.remote_enable都為on:

如何使用Visual Studio Code除錯PHP CLI應用和Web應用

然後安裝Visual Studio Code的擴充套件:PHP Debug

如何使用Visual Studio Code除錯PHP CLI應用和Web應用

安裝完畢後,File->Preferences->Settings:

如何使用Visual Studio Code除錯PHP CLI應用和Web應用

新增一條entry:php.validate.executablePath, 指向你本地的php.exe

建立一個PHP debug configuration,有兩種方式選擇:
Launch current open script和Listen for Xdebug:

如何使用Visual Studio Code除錯PHP CLI應用和Web應用


如何使用Visual Studio Code除錯PHP CLI應用和Web應用
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?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": 9000,            "runtimeExecutable":"C:\\MyApp\\wamp20190709\\bin\\php\\php7.0.10\\php.exe"
        }
    ]
}

前者除錯PHP CLI應用比較方便,開啟一個php檔案,直接F5,斷點即觸發。

如何使用Visual Studio Code除錯PHP CLI應用和Web應用


如何使用Visual Studio Code除錯PHP CLI應用和Web應用

如果選擇成Listen for XDebug,同樣先F5啟動除錯程式,

如何使用Visual Studio Code除錯PHP CLI應用和Web應用

然後瀏覽器裡訪問待除錯的PHP檔案,Visual Studio Code的斷點即觸發,可以單步除錯了:

如何使用Visual Studio Code除錯PHP CLI應用和Web應用

要獲取更多Jerry的原創文章,請關注公眾號"汪子熙":


如何使用Visual Studio Code除錯PHP CLI應用和Web應用


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24475491/viewspace-2651684/,如需轉載,請註明出處,否則將追究法律責任。

相關文章