通过函数计算的Custom Runtime,您可以使用PHP 7.4在函数计算平台编写函数。本文介绍快速部署和调用PHP函数的详细步骤。您也可以按需修改PHP示例中的代码实现二次开发。
操作步骤
- 执行以下命令,初始化项目。
s init fc-custom-php74-event -d fc-custom-php74-event
说明 -d
用于指定该示例项目文件夹的名称,支持自定义。
- 执行以下命令,进入项目目录。
- 可选:按需修改函数的示例代码,实现二次开发。
- 执行以下命令,部署项目。
s deploy -y
输出示例:
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
- 执行以下命令,远程调用函数。
s invoke -e "hello"
输出示例:
========= 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