本文以函数名demo为例介绍如何通过VSCode调试PHP函数。
操作步骤
- 执行以下命令调试PHP函数。
fun local invoke -d 3000 --config VSCode demo
预期输出:
using template: template.yml
skip pulling image aliyunfc/runtime-php7.2:1.9.6...
using remote_ip 192.168.xx.xx
you can paste these config to .vscode/launch.json, and then attach to your running function
///////////////// config begin /////////////////
{
"version": "0.2.0",
"configurations": [
{
"name": "fc/demo/demo",
"type": "php",
"request": "launch",
"port": 3000,
"stopOnEntry": false,
"pathMappings": {
"/code": "C:\\Users\\jjj\\Desktop\\ggg\\demo"
},
"ignore": [
"/var/fc/runtime/**"
]
}
]
}
///////////////// config end /////////////////
FunctionCompute php7.2 runtime inited.
FC Invoke Start RequestId: 6b83670b-f915-4790-8362-d549****
2021-04-28T12:07:30Z 6b83670b-f915-4790-8362-d549c39b**** [INFO]: hello world
FC Invoke End RequestId: 6b83670b-f915-4790-8362-d549****
hello world
RequestId: 6b83670b-f915-4790-8362-d549c****** Billed Duration: 688 ms Memory Size: 1991 MB Max Memory Used: 62 MB
- 配置VSCode。
注意 由于PHP程序需要先启动VSCode的调试器,在执行调试的命令时并未阻止等待VSCode调试器的连接,而是直接调试结束。所以您需要在第一次使用VSCode时配置VSCode,如果已配置,则无需再次配置。
- 选择,创建launch.json文件。
- 复制输出日志
config begin
与config end
之间的信息至launch.json中。如果您需要了解更多VSCode的详细信息,请参见VSCode。
完成上面配置后,在Debug视图中您可以查看到配置的函数列表。

- 使用VSCode调试PHP函数。
- 执行以下命令再次调试PHP函数即可。
fun local invoke -d 3000 demo