This topic describes how to use SDK for PHP.

Installation

Run the following composer command to install SDK for PHP:

composer require alibabacloud/fnf         

If the download speed is slow, you can switch to the composer image in China.

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

Alibaba Cloud SDK for PHP is also released at https://github.com/aliyun/openapi-sdk-php. For more information, see README-zh-CN.

Quick start

You must have an Alibaba Cloud account and an AccessKey pair to use SDK for PHP. Example:

<? php

// If you use composer to download and debug dependencies locally, add the following reference:
require 'vendor/autoload.php';

use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;
use AlibabaCloud\Fnf\Fnf;

// Set the global client.
AlibabaCloud::accessKeyClient('foo', 'bar')
            ->regionId('cn-hangzhou')
            ->asDefaultClient();

try {
    // Access API operations of the service.
    $request1 = Fnf::v20190315()->createFlow();

    // Set options and parameters and execute requests.
    // Create a flow.
    $result1 = $request1->withDefinition('xxx') // API parameters
                                   ->withName('xxx')
                                   ->withRoleArn('xxx')
                                   ->withDescription('xxx')
                                   ->withType('FDL')
                                   //->scheme("https")
                                   //->client('client1') // Specifies the sending client. Otherwise, the global client is used.
                                   ->debug(true) // Outputs details. If this field is set to false, details are not output.
                                   ->connectTimeout(10) // Throws an exception when the connection times out.
                                   ->timeout(10) // Throws an exception upon timeout.
                                   ->request(); // Executes requests.

    // Start an execution.
    // The following example shows how to use options to pass in parameters related to SDK calls.
    // You can also use withxxx to call SDK for PHP by referring to $request1.
    $options = [
                   'debug'=>true,
                   'connect_timeout'=>10,
                   'timeout'=>10,
                   'form_params'=>[
                       'FlowName'=>'xxx',
                       'Input'=>'{"execID": "exe1"}',
                   ],
               ];

    $result2 = Fnf::v20190315()
                                   ->startExecution($options)
                                   ->options([
                                       'form_params'=>[
                                           'Input'=>'Overwrites the value of the Input parameter in options, in json format'.
                                       ],
                                   ])
                                   ->debug(false) // The last call will overwrite the former ones.
                                   ->request();

    // Query the execution result.
    $request3 = Fnf::v20190315()->getExecutionHistory();

    // Set options and parameters and execute requests.
    // Create a flow.
    $result3 = $request3->withFlowName('xxx') // API parameters
                                   ->withExecutionName('xxx')
                                   ->debug(true) // Outputs details. If this field is set to false, details are not output.
                                   ->connectTimeout(10) // Throws an exception when the connection times out.
                                   ->timeout(10) // Throws an exception upon timeout.
                                   ->request(); // Executes requests.

} catch (ClientException $exception) {
    echo $exception->getMessage().PHP_EOL;
} catch (ServerException $exception) {
    echo $exception->getMessage().PHP_EOL;
    echo $exception->getErrorCode().PHP_EOL;
    echo $exception->getRequestId().PHP_EOL;
    echo $exception->getErrorMessage().PHP_EOL;
}