Yandex Cloud
Search
Contact UsGet started
  • Blog
  • Pricing
  • Documentation
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • ML & AI
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Customer Stories
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
    • Yandex Cloud Partner program
  • Blog
  • Pricing
  • Documentation
© 2025 Direct Cursus Technology L.L.C.
Yandex Cloud Functions
  • Comparison with other Yandex Cloud services
    • Overview
    • Managing dependencies
    • Request handler
    • Invocation context
    • Logging
    • Handling errors
  • Tools
  • Pricing policy
  • Access management
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • Release notes
  • FAQ

In this article:

  • Examples
  • HTTP request structure output
  • Synchronous handler
  1. Developing in PHP
  2. Request handler

PHP function call handler

Written by
Yandex Cloud
Updated at February 27, 2023
  • Examples
    • HTTP request structure output
    • Synchronous handler

A call handler is a method used to handle each PHP function call. When creating a function version, you should specify the entry point that consists of the file name and request handler name (for example, index.myFunction).

Note

At any given time, a single function instance processes only one request. This lets you use global variables without having to provide data integrity control.

When invoking the handler, the runtime passes the following arguments:

  1. Call body (event parameter).

    If the request body is a JSON document, it's converted to an Array using the json_decode method.

  2. The invocation context (the context parameter).

    The context contains the necessary information about the function version. The structure of this object is described in PHP function invocation context.

A handler is a function that is declared in a global namespace and takes two arguments.

To have the execution result returned, use the return statement or throw an exception using the throw statement.

ExamplesExamples

HTTP request structure outputHTTP request structure output

The following function outputs the request structure and invocation context to both the execution log and function response:

<?php

function myHandler ($event, $context) {
    $resp = [
        'event' => $event,
        'context' => $context,
    ];

    return [
        'statusCode' => 200,
        'body' => json_encode($resp),
    ];
}

Synchronous handlerSynchronous handler

The function returns the available response or an error:

<?php

function myHandler ($event, $context) {
    $message = "not lucky";
    if (rand() % 2 == 0) {
        $message = "lucky one";
    }

    return [
        'statusCode' => 200,
        'headers' => [
            'Content-Type' => 'text/plain',
        ],
        'body' => $message,
    ];
}

Was the article helpful?

Previous
Managing dependencies
Next
Invocation context
© 2025 Direct Cursus Technology L.L.C.