Alibaba Cloud SDK for PHP - Easier to Use Alibaba Cloud in your PHP project

1.2.4 2019-03-19 11:12 UTC


English | 简体中文


Latest Stable Version Latest Unstable Version composer.lock Total Downloads License
codecov Scrutinizer Code Quality Travis Build Status Appveyor Build Status Code Intelligence Status


Alibaba Cloud SDK for PHP is a development kit that supports quick access to products, dependency on Alibaba Cloud Client for PHP.

Release Notes

We developed a new kernel on the principle of eliminating known issues and compatible with old grammar, adding the following features:

Getting Started

  1. Alibaba Cloud Account – Before you begin, you need to sign up for an Alibaba Cloud account and retrieve your Credentials.
  2. Requirements – Your system will need to meet the Requirements, including having PHP >= 5.5. We highly recommend having it compiled with the cURL extension and cURL 7.16.2+.
  3. Install Dependency – If Composer is installed globally on your system, you can run the following in the base directory of your project to add the Alibaba Cloud SDK for PHP as a dependency:
    composer require alibabacloud/sdk
    Please see the Installation for more detailed information about installing through Composer and other means.
  4. Optimize automatic loading - This command must be executed, otherwise it may not be available.
    composer dump-autoload --optimize

Online Demo

API Explorer provides the ability to call the cloud product OpenAPI online, and dynamically generate SDK Example code and quick retrieval interface, which can significantly reduce the difficulty of using the cloud API.

Quick Examples

Before request, please Understanding the Clients, after request, please Understanding the Result.

Currently only some Alibaba Cloud products are supported, Supported Products, For products that are not supported, you can use Alibaba Cloud Client for PHP to initiate custom requests, and you can use API Explorer to generate Alibaba Cloud Client for PHP code online.


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

// Set up a global client
AlibabaCloud::accessKeyClient('foo', 'bar')

try {
    // Access product APIs
    $request = AlibabaCloud::ecs()->v20140526()->describeRegions();
    // Set options/parameters and execute request
    $result = $request->withResourceType('type') // API parameter
                      ->withInstanceChargeType('type') // API parameter
                      ->client('client1') // Specify the client for send
                      ->debug(true) // Enable the debug will output detailed information
                      ->connectTimeout(0.01) // Throw an exception when Connection timeout 
                      ->timeout(0.01) // Throw an exception when timeout 
                      ->request(); // Execution request

    // Can also Set by passing in an array
    $options = [
                   'debug'           => true,
                   'connect_timeout' => 0.01,
                   'timeout'         => 0.01,
                   'query'           => [
                       'ResourceType' => 'type',
                       'InstanceChargeType' => 'type',
    // Settings priority
    $result2 = AlibabaCloud::ecs()
                                         'query' => [
                                             'Key'      => 'I will overwrite this value in constructor',
                                             'new'      => 'I am new value',
                                         'query' => [
                                             'Key' => 'I will overwrite the previous value',
                                             'bar' => 'I am new value',
                           ->debug(false) // Overwrite the true of the former
} 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;