通过函数计算的Custom Runtime,您可以使用PHP 7.4在函数计算平台编写函数。本文介绍快速部署和调用PHP函数的详细步骤。您也可以按需修改PHP示例中的代码实现二次开发。

前提条件

您已完成以下操作:

操作步骤

  1. 在目标目录中,执行以下命令,初始化项目。
    s init start-fc-custom-samples -d start-fc-custom-samples
  2. 执行以下命令,进入项目目录。
    cd start-fc-custom-samples/php74/event-demo/
  3. 执行以下命令,部署项目。
    s deploy -y
    输出示例:
    [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. 执行以下命令,远程调用函数。
    s invoke -e "hello"
    输出示例:
    [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