This topic describes how to install and use CloudMonitor SDK for PHP.

Background information

Install CloudMonitor SDK for PHP

You can download the installation packages of the SDKs for PHP from the following links:

Sample code

The following sample code provides an example on how to use CloudMonitor SDK for PHP to call the CloudMonitor API operation DescribeMetricList. For other operations, you can use OpenAPI Explorer to debug the operations and obtain sample code.

For more information about the request parameters of the DescribeMetricList operation, see DescribeMetricList.

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

// Download URL:
// User guide:
// Construct an Alibaba Cloud client to initiate requests. 
// When you construct the client, specify your AccessKey ID and AccessKey secret. 
AlibabaCloud::accessKeyClient('<accessKeyId>', '<accessSecret>')
# Specify the request parameters. 
try {
    $result = AlibabaCloud::rpc()
                          // ->scheme('https') // https | http
                                        'query' => [
                                          'RegionId' => "cn-hangzhou",
                                          'MetricName' => "cpu_total",
                                          'Namespace' => "acs_ecs_dashboard",
                                          'StartTime' => "1628055731050",
                                          'EndTime' => "1628062931050",
                                          'Dimensions' => "{\"instanceId\":\"i-0xii2bvf42iqvxbp****\"}",
                                          'Length' => "10",
} catch (ClientException $e) {
    echo $e->getErrorMessage() . PHP_EOL;
} catch (ServerException $e) {
    echo $e->getErrorMessage() . PHP_EOL;