This topic describes how to install CloudMonitor SDK for PHP and provides sample code.
Background information
- Alibaba Cloud provides OpenAPI Explorer to simplify API usage. You can use OpenAPI Explorer to debug API operations and dynamically generate SDK sample code.
- For more information about the CloudMonitor API, see List of API operations by function.
Install CloudMonitor SDK for PHP
For more information about how to install CloudMonitor SDK for PHP, see Quick start.
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.
<?php
use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;
// Download URL: https://github.com/aliyun/openapi-sdk-php
// User guide: https://github.com/aliyun/openapi-sdk-php/blob/master/README.md
// Construct an Alibaba Cloud client to initiate requests.
// When you construct the client, specify your AccessKey ID and AccessKey secret.
AlibabaCloud::accessKeyClient('<accessKeyId>', '<accessSecret>')
->regionId('cn-hangzhou')
->asDefaultClient();
# Specify the request parameters.
try {
$result = AlibabaCloud::rpc()
->product('Cms')
// ->scheme('https') // Valid value: https and http.
->version('2019-01-01')
->action('DescribeMetricList')
->method('POST')
->host('metrics.aliyuncs.com')
->options([
'query' => [
'RegionId' => "cn-hangzhou",
'MetricName' => "cpu_total",
'Namespace' => "acs_ecs_dashboard",
'StartTime' => "1628055731050",
'EndTime' => "1628062931050",
'Dimensions' => "{\"instanceId\":\"i-0xii2bvf42iqvxbp****\"}",
'Length' => "10",
],
])
->request();
print_r($result->toArray());
} catch (ClientException $e) {
echo $e->getErrorMessage() . PHP_EOL;
} catch (ServerException $e) {
echo $e->getErrorMessage() . PHP_EOL;
}