You can use the custom runtime of Function Compute to write functions in Function Compute by using PHP 7.4. This topic describes how to deploy and invoke a PHP function. You can modify the PHP sample code to perform secondary development.

Prerequisites

The following operations are complete:

Procedure

  1. Run the following command in the target directory to initialize the project:
    s init start-fc-custom-samples -d start-fc-custom-samples
  2. Run the following command to go to the project directory:
    cd start-fc-custom-samples/php74/event-demo/
  3. Run the following command to deploy the project:
    s deploy -y
    Sample output:
    [2021-09-09T10:24:52.179] [INFO ] [S-CLI] - Start ...
    [2021-09-09T10:24:52.703] [INFO ] [FC-DEPLOY] - Using region: cn-hangzhou
    [2021-09-09T10:24:52.704] [INFO ] [FC-DEPLOY] - Using access alias: default
    [2021-09-09T10:24:52.707] [INFO ] [FC-DEPLOY] - Using accessKeyID: 188077086902****
    [2021-09-09T10:24:52.707] [INFO ] [FC-DEPLOY] - Using accessKeySecret: LTAI4G4cwJkK4Rza6xd9****
     Using fc deploy type: sdk, If you want to deploy with pulumi, you can [s cli fc-default set deploy-type pulumi] to switch.
    [2021-09-09T10:24:53.100] [INFO ] [FC-DEPLOY] - Checking Service custom-demo exists
    [2021-09-09T10:24:53.313] [INFO ] [FC-DEPLOY] - Checking Function php74EventFunc exists
     Make service custom-demo success.
     Make function custom-demo/php74EventFunc success.
    [2021-09-09T10:24:54.002] [INFO ] [FC-DEPLOY] - Checking Service custom-demo exists
    [2021-09-09T10:24:54.094] [INFO ] [FC-DEPLOY] - Checking Function php74EventFunc exists
    
    Tips for next step
    ======================
    * Display information of the deployed resource: s info
    * Display metrics: s metrics
    * Display logs: s logs
    * Invoke remote function: s invoke
    * Remove Service: s remove service
    * Remove Function: s remove function
    * Remove Trigger: s remove trigger
    * Remove CustomDomain: s remove domain
    
    
    
    fc-php74-demo-fc-php74-swoole:
      region: cn-hangzhou
      service:
        name: custom-demo
      function:
        name: php74EventFunc
        runtime: custom
        handler: server.handler
        memorySize: 1024
        timeout: 30
  4. Run the following command to invoke the function:
    s invoke -e "hello"
    Sample output:
    [2021-09-09T10:25:44.508] [INFO ] [S-CLI] - Start ...
    ========= FC invoke Logs begin =========
    
    Duration: 3.37 ms, Billed Duration: 4 ms, Memory Size: 1024 MB, Max Memory Used: 86.30 MB
    ========= FC invoke Logs end =========
    
    FC Invoke Result:
    hello
    
    
    End of method: invoke