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 as needed for custom development.

Procedure

  1. Run the following command to initialize a project:
    s init fc-custom-php74-event -d fc-custom-php74-event
    Note -d specifies the name of the folder in which the sample project resides. You can customize the folder name as required.
  2. Run the following command to go to the project directory:
    cd fc-custom-php74-event
  3. Optional: Modify the sample code as needed for custom development.
  4. Run the following command to deploy the project:
    s deploy -y
    Sample command output:
     Checking Service, Function (1.3s)
     Creating Service, Function (0.61s)
    
    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
    
    helloworld:
      region:   cn-hangzhou
      service:
        name: hello-world-service
      function:
        name:       php74EventFunc
        runtime:    custom
        handler:    index.handler
        memorySize: 1024
        timeout:    30
  5. Run the following command to remotely invoke the function:
    s invoke -e "hello"
    Sample command output:
    ========= FC invoke Logs begin =========
    
    Duration: 81.65 ms, Billed Duration: 82 ms, Memory Size: 1024 MB, Max Memory Used: 78.31 MB
    ========= FC invoke Logs end =========
    
    FC Invoke Result:
    hello
    
    
    End of method: invoke