tencent cloud

Serverless Cloud Function

Release Notes and Announcements
Release Notes
Announcements
User Guide
Product Introduction
Overview
Related Concepts
How It Works
Strengths
Scenarios
Related Products
Purchase Guide
Billing Overview
Billing Mode
Billable Items and Billing Modes
Function Computing Power Support
Free Tier
SCF Pricing
Billing Example
Payment Overdue
Getting Started
Creating Event Function in Console
User Guide
Quota Management
Managing Functions
Web Function Management
Log Management
Concurrence Management
Trigger Management
Function URL
A Custom Domain Name
Version Management
Alias Management
Permission Management
Running Instance Management
Plugin Management
Managing Monitors and Alarms
Network Configuration
Layer Management
Execution Configuration
Extended Storage Management
DNS Caching Configuration
Resource Managed Mode Management
Near-Offline Resource Hosting Model
Workflow
Triggers
Trigger Overview
Trigger Event Message Structure Summary
API Gateway Trigger
COS Trigger
CLS Trigger
Timer Trigger
CKafka Trigger
Apache Kafka Trigger
MQTT Trigger
Trigger Configuration Description
MPS Trigger
CLB Trigger Description
TencentCloud API Trigger
Development Guide
Basic Concepts
Testing a Function
Environment Variables
Dependency Installation
Using Container Image
Error Types and Retry Policies
Dead Letter Queue
Connecting SCF to Database
Automated Deployment
Cloud Function Status Code
Common Errors and Solutions
Developer Tools
Serverless Web IDE
Calling SDK Across Functions
Third-Party Tools
Code Development
Python
Node.js
Golang
PHP
Java
Custom Runtime
Deploying Image as Function
Web Framework Development
Deploying Framework on Command Line
Quickly Deploying Egg Framework
Quickly Deploying Express Framework
Quickly Deploying Flask Framework
Quickly Deploying Koa Framework
Quickly Deploying Laravel Framework
Quickly Deploying Nest.js Framework
Quickly Deploying Next.js Framework
Quickly Deploying Nuxt.js Framework
Quickly Deploying Django Framework
Use Cases
Overview
Solutions with Tencent Cloud Services
Business Development
TRTC Practices
COS Practices
CKafka Practice
CLS
CLB Practice
MPS
CDN
CDWPG
VOD
SMS
ES
Scheduled Task
Video Processing
Success Stories
Tencent Online Education
Online Video Industry
Tencent Online Education
Best Practice of Tencent IEG Going Global
API Documentation
History
Introduction
API Category
Making API Requests
Other APIs
Namespace APIs
Layer Management APIs
Async Event Management APIs
Trigger APIs
Function APIs
Function and Layer Status Description
Data Types
Error Codes
SDK Documentation
FAQs
General
Web Function
Billing FAQs
Network FAQs
Log FAQs
SCF utility class
Event Handling FAQs
API Gateway Trigger FAQs
Related Agreement
Service Level Agreement
Contact Us
Glossary

Development Methods

PDF
フォーカスモード
フォントサイズ
最終更新日: 2024-12-02 18:12:22

Function Format

The PHP function format is generally as follows:
<?php
function main_handler($event, $context) {
print_r ($event);
print_r ($context);
return "hello world";
}
?>

Execution Method

You need to specify the execution method when creating a SCF function. If the PHP programming language is used, the execution method is similar to index.main_handler, where index indicates that the executed entry file is index.php, and main_handler indicates that the executed entry function is main_handler.
When submitting the ZIP code package by uploading the ZIP file locally or through COS, make sure that the root directory of the ZIP package contains the specified entry file, which contains the entry function specified by the definition, file name, function name, and execution method; otherwise, execution will fail as the entry file or entry function cannot be found.

Input Parameters

The input parameters in the PHP environment include $event and $context.
$event: This parameter is used to pass the trigger event data.
$context: This parameter is used to pass runtime information to your handler.
The event parameter varies with trigger or event source. For more information on its data structure, see Trigger Overview.
Note:
The input parameters event and context in PHP 8.0, 7.4, 7.2, and 5.6 are in object format.

Response

Your handler can use return to return a value. The return value will be handled differently depending on the type of invocation when the function is invoked.
In the PHP environment, a serializable object such as dict object can be directly returned:
Sync invocation: The return value of a sync invocation will be serialized in JSON and returned to the caller for subsequent processing. The function testing in the console is sync invocation, which can capture the function’s return value and display it after the invocation is completed.
Async invocation: The return value of an async invocation will be discarded, since the invocation method responds right after the function is triggered, without waiting for function execution to complete.
Note:
The return value of both sync and async invocations will be recorded in the function logs. The return value will be written to the function invocation log SCF_Message in the format of Response RequestId:xxx RetMsg:xxx.
The value of SCF_Message is limited to 8 KB in length, and excessive parts will be truncated.

Exception Handling

You can exit the function by calling die(). At this point, the function will be marked as execution failed, and the output from the exit using die() will also be recorded in the log.

ヘルプとサポート

この記事はお役に立ちましたか?

フィードバック