This topic uses the function name demo as an example to describe how to debug a PHP function by using VSCode.

Notice The content described in this article will no longer be maintained later. If your Function service resources are managed by Funcraft, we recommend that you migrate the resources to Serverless Devs.

For more information about how to migrate Function Compute-related resources from Funcraft to Serverless Devs, see Migrate resources from Funcraft to Serverless Devs.

For more information about Serverless Devs, see Overview.

For more information about how to use Serverless Devs to debug functions, see Debug Functions and Remote debug Using s Local Related Commands.

We apologize for any inconvenience caused.

Procedure

  1. Run the following command to debug PHP functions:
    fun local invoke -d 3000 --config VSCode demo
    Expected output:
    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
          
  2. Configure VSCode.
    Notice Since the PHP program needs to start the debugger of VSCode first, it does not prevent waiting for the connection of VSCode debugger when executing the debugging command, but directly ends the debugging. Therefore, you need to configure VSCode when you use VSCode for the first time. If it is already configured, you do not need to configure it again.
  3. Use VSCode to debug PHP functions.
  4. Run the following command to debug the PHP function again:
    fun local invoke -d 3000 demo