All Products
Search
Document Center

CloudFlow:Install CloudFlow SDK for PHP

Last Updated:Mar 11, 2026

This topic describes how to install the CloudFlow PHP SDK, initialize a client, and call API operations to create, query, and start workflow executions.

Prerequisites

Before you begin, make sure that you have:

Important

The PHP version used to install the SDK through Composer must be earlier than or equal to the PHP version used to run the SDK. For example, a vendor folder generated on PHP 7.2 works only on PHP 7.2 or later. If Composer installation fails due to network issues, switch to the Alibaba Cloud mirror:

composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/

Step 1: Install the SDK

CloudFlow SDK supports two call types. Choose one based on your use case:

  • Specialized calls (recommended) -- Typed request and response classes for each API operation, with IDE autocompletion and compile-time checks.

  • Generic calls -- A single core package to call any Alibaba Cloud API without service-specific classes.

For more information about the differences, see Generic calls and specialized calls.

Specialized calls

Run the following command to install the CloudFlow SDK package:

composer require alibabacloud/fnf-20190315 1.1.3

To find the latest version and installation instructions, visit the CloudFlow SDK page in OpenAPI Explorer. Select PHP in the All languages field, then copy the installation code from the Installation Method section.

Generic calls

Install the darabonba-openapi core package instead of a service-specific SDK:

composer require alibabacloud/darabonba-openapi

For the latest version, see tea-openapi.

Step 2: Initialize the client

Set the endpoint based on the region where you use CloudFlow. The endpoint format is {region-id}.fnf.aliyuncs.com. For a full list of supported regions and endpoints, see Regions.

The following example initializes a client for specialized calls by using an AccessKey pair stored in environment variables. For other authentication methods, see Manage access credentials. To configure environment variables, see Configure environment variables in Linux, macOS, and Windows.

To initialize a client for generic calls, see Generic calls and specialized calls.

Note

The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. We recommend that you use a Resource Access Management (RAM) user to call API operations or perform routine O&M. Do not save AccessKey credentials in your project code. Store them in environment variables instead.

<?php

require_once __DIR__ . '/../vendor/autoload.php';

use AlibabaCloud\SDK\Fnf\V20190315\Fnf;
use Darabonba\OpenApi\Models\Config;

$config = new Config([
    // Make sure that ALIBABA_CLOUD_ACCESS_KEY_ID is set in your environment
    "accessKeyId" => getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
    // Make sure that ALIBABA_CLOUD_ACCESS_KEY_SECRET is set in your environment
    "accessKeySecret" => getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),
]);

// Replace with your region endpoint. Example: cn-hangzhou.fnf.aliyuncs.com
$config->endpoint = "cn-hangzhou.fnf.aliyuncs.com";

$client = new Fnf($config);

Step 3: Call API operations

After you initialize a client, use it to call CloudFlow API operations. All examples in this topic share the same client initialization and error handling pattern.

Handle errors

Wrap every API call in error handling. The following pattern applies to all examples in this topic:

use \Exception;
use AlibabaCloud\Tea\Exception\TeaError;
use AlibabaCloud\Tea\Utils\Utils;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;

$runtime = new RuntimeOptions([]);

try {
    // API call goes here
} catch (Exception $error) {
    if (!($error instanceof TeaError)) {
        $error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
    }
    var_dump($error->message);
    var_dump($error->data["Recommend"]);
    Utils::assertAsString($error->message);
}

CreateFlow

Call CreateFlow to create a workflow. Define the workflow by using Flow Definition Language (FDL). CloudFlow supports both the legacy and current FDL syntax.

use AlibabaCloud\SDK\Fnf\V20190315\Models\CreateFlowRequest;

$createFlowRequest = new CreateFlowRequest([
    "name" => "my_flow_name",
    "definition" => '
Type: StateMachine
SpecVersion: v1
Name: my_flow_name
StartAt: my_state
States:
  - Type: Pass
    Name: my_state
    End: true
',
    "description" => "your test flow",
    "type" => "FDL"
]);

$runtime = new RuntimeOptions([]);
$client->createFlowWithOptions($createFlowRequest, $runtime);
ParameterDescriptionExample
nameWorkflow namemy_flow_name
definitionWorkflow definition in FDL syntaxSee code above
descriptionWorkflow descriptionyour test flow
typeDefinition language typeFDL

Legacy FDL syntax

type: flow
version: v1
name: my_flow_name
steps:
  - type: pass
    name: mypass

DescribeFlow

Call DescribeFlow to query information about a workflow.

use AlibabaCloud\SDK\Fnf\V20190315\Models\DescribeFlowRequest;

$describeFlowRequest = new DescribeFlowRequest([
    "name" => "my_flow_name"
]);

$runtime = new RuntimeOptions([]);
$client->describeFlowWithOptions($describeFlowRequest, $runtime);

StartExecution

Call StartExecution to start a workflow execution asynchronously.

use AlibabaCloud\SDK\Fnf\V20190315\Models\StartExecutionRequest;

$startExecutionRequest = new StartExecutionRequest([
    "flowName" => "your_flow_name",
    "executionName" => "your_exec_name",
    "input" => '{"key":"value"}',
    // Call back TaskToken-related tasks after the execution ends
    "callbackFnFTaskToken" => "12"
]);

$runtime = new RuntimeOptions([]);
$client->startExecutionWithOptions($startExecutionRequest, $runtime);
ParameterDescriptionExample
flowNameName of the workflow to runyour_flow_name
executionNameName for this executionyour_exec_name
inputJSON input for the execution{"key":"value"}
callbackFnFTaskTokenToken for TaskToken callback tasks after the execution ends12

Complete example

The following example creates a workflow, queries its details, and starts an execution:

<?php

namespace AlibabaCloud\SDK\Sample;

$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
    require_once $path;
}

use AlibabaCloud\SDK\Fnf\V20190315\Fnf;
use AlibabaCloud\SDK\Fnf\V20190315\Models\CreateFlowRequest;
use AlibabaCloud\SDK\Fnf\V20190315\Models\DescribeFlowRequest;
use AlibabaCloud\SDK\Fnf\V20190315\Models\StartExecutionRequest;
use AlibabaCloud\Tea\Exception\TeaError;
use AlibabaCloud\Tea\Utils\Utils;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use Darabonba\OpenApi\Models\Config;
use \Exception;

class Sample
{
    public static function createClient()
    {
        $config = new Config([
            "accessKeyId" => getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
            "accessKeySecret" => getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),
        ]);
        // Replace with your region endpoint. Example: cn-hangzhou.fnf.aliyuncs.com
        $config->endpoint = "cn-hangzhou.fnf.aliyuncs.com";

        return new Fnf($config);
    }

    public static function main($args)
    {
        $client = self::createClient();
        $runtime = new RuntimeOptions([]);

        try {
            // Create a workflow
            $createFlowRequest = new CreateFlowRequest([
                "name" => "my_flow_name",
                "definition" => '
Type: StateMachine
SpecVersion: v1
Name: my_flow_name
StartAt: my_state
States:
  - Type: Pass
    Name: my_state
    End: true
',
                "description" => "your test flow",
                "type" => "FDL"
            ]);
            $client->createFlowWithOptions($createFlowRequest, $runtime);

            // Query workflow details
            $describeFlowRequest = new DescribeFlowRequest([
                "name" => "my_flow_name"
            ]);
            $client->describeFlowWithOptions($describeFlowRequest, $runtime);

            // Start an execution
            $startExecutionRequest = new StartExecutionRequest([
                "flowName" => "your_flow_name",
                "executionName" => "your_exec_name",
                "input" => '{"key":"value"}',
                // Call back TaskToken-related tasks after the execution ends
                "callbackFnFTaskToken" => "12"
            ]);
            $client->startExecutionWithOptions($startExecutionRequest, $runtime);

        } catch (Exception $error) {
            if (!($error instanceof TeaError)) {
                $error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
            }
            var_dump($error->message);
            var_dump($error->data["Recommend"]);
            Utils::assertAsString($error->message);
        }
    }
}

Sample::main(array_slice($argv, 1));

More examples

For API-level SDK demos in PHP and other languages, see OpenAPI Explorer.

What's next