如何使用Visual Studio Code调试PHP CLI应用和Web应用

在按照Jerry的公众号文章 什么?在SAP中国研究院里还需要会PHP开发? 进行XDebug在本地的配置之后,如果想使用Visual Studio Code而不是Eclipse来调试PHP应用,步骤也比较简单。

启动WAMP服务器,确保xdebug.remote_autostart, xdebug.remote_enable都为on:

webp

然后安装Visual Studio Code的扩展:PHP Debug

webp

安装完毕后,File->Preferences->Settings:

webp

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

创建一个PHP debug configuration,有两种方式选择:
Launch current open script和Listen for Xdebug:

webp


webp
{
    // 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,断点即触发。

webp


webp

如果选择成Listen for XDebug,同样先F5启动调试进程,

webp

然后浏览器里访问待调试的PHP文件,Visual Studio Code的断点即触发,可以单步调试了:

webp

要获取更多Jerry的原创文章,请关注公众号"汪子熙":


webp


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/24475491/viewspace-2651684/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/24475491/viewspace-2651684/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值