如何使用Visual Studio Code調試PHP CLI應用和Web應用

在按照Jerry的公衆號文章 什麼?在SAP中國研究院裏還須要會PHP開發? 進行XDebug在本地的配置以後,若是想使用Visual Studio Code而不是Eclipse來調試PHP應用,步驟也比較簡單。php

啓動WAMP服務器,確保xdebug.remote_autostart, xdebug.remote_enable都爲on:json

而後安裝Visual Studio Code的擴展:PHP Debug瀏覽器

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

添加一條entry:php.validate.executablePath, 指向你本地的php.exephp7

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

{
    // 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,斷點即觸發。3d

若是選擇成Listen for XDebug,一樣先F5啓動調試進程,調試

而後瀏覽器裏訪問待調試的PHP文件,Visual Studio Code的斷點即觸發,能夠單步調試了:code

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

相關文章
相關標籤/搜索