When you use PHP for programming in Function Compute, you must define a PHP function as the handler function. This topic describes the structure and features of PHP initializer functions.

Definition

The following code defines a simple initializer function.

<? php
function my_initializer($context) {
    $logger = $GLOBALS['fcLogger'];
    $logger->info("hello world");
}
? >            

Function name

The my_initializer parameter must correspond to the initializer field that you specify when you add the initializer feature. For example, if you set initializer to main.my_initializer when you create a function, after the initializer feature is configured, Function Compute loads the my_initializer function defined in the main.php file.

Features

  • An initializer function has only one input parameter: the context parameter. This parameter is defined the same as the context parameter in event functions.
  • In the context parameter, the initializer and initializationTimeout fields are specifically designed for initializer functions. If these two fields are not specified, the initializer function will not be executed.
  • Initializer functions do not return any value. Return logic appended to initializer functions does not take effect.

References

For more information about initializer functions, see Initializer function.