The process of creating PHP actions is similar to that of other actions.
The following sections guide you through creating and invoking a single PHP action, and demonstrate how to bundle multiple PHP files and third party dependencies.
PHP actions are executed using PHP 8.0, 7.4 or 7.3. The specific version of PHP is listed in the CHANGELOG files in the PHP runtime repository.
To use a PHP runtime, specify the
wsk CLI parameter
--kind when creating or
updating an action. The available PHP kinds are:
- PHP 8.0:
- PHP 7.4:
- PHP 7.3:
An action is simply a top-level PHP function. For example, create a file called
with the following source code:
PHP actions always consume an associative array and return an associative array.
The entry method for the action is
main by default but may be specified explicitly when creating
the action with the
wsk CLI using
--main, as with any other action type.
You can create an OpenWhisk action called
helloPHP from this function as follows:
The CLI automatically infers the type of the action from the source file extension.
.php source files, the action runs using a PHP 7.4 runtime.
Action invocation is the same for PHP actions as it is for any other action.
Find out more about parameters in the Working with parameters section.
You can package a PHP action along with other files and dependent packages in a zip file.
The filename of the source file containing the entry point (e.g.,
main) must be
For example, to create an action that includes a second file called
first create an archive containing your source files:
and then create the action:
If your PHP action requires Composer dependencies, you can install them as usual using
composer require which will create a
Add this directory to your action's zip file and create the action:
The PHP runtime will automatically include Composer's autoloader for you, so you can immediately
use the dependencies in your action code. Note that if you don't include your own
then the runtime will include one for you with the following Composer packages:
The specific versions of these packages depends on the PHP runtime in use and is listed in the CHANGELOG files in the PHP runtime repository.
The following PHP extensions are available in addition to the standard ones:
Large portions of this page is copied from the Apache OpenWhisk documentation on April 23rd 2021 - where there have been customisations to match Hypi's deployment this has been noted. Apache OpenWhisk and the Apache name are the property of the Apache Foundation and licensed under the Apache V2 license .