This topic describes how to install and use Log Service SDK for PHP.
- Log Service is activated. For more information, see Activate Log Service.
- An AccessKey pair is created and obtained. For more information, see AccessKey pair.
- A PHP development environment is installed.
Log service SDK for PHP supports PHP version 5.2.1 and later. You can run the php -V command to check the version of PHP that you have installed.
Install Log Service SDK for PHP
- Download the latest Log Service SDK for PHP.
- Decompress the aliyun-log-php-sdk-master.zip package to a specified directory.The SDK for PHP does not require installation. The SDK for PHP contains SDK code, a set of third-party dependencies, and an Autoloader class. This simplifies the process of SDK calls.
Step 2: Create Aliyun_Log_Client
$endpoint = 'cn-hangzhou.sls.aliyuncs.com '; // The endpoint of Log Service. For more information, see Endpoints. The endpoint of the China (Hangzhou) region is used as an example. Replace it with the actual endpoint. $accessKeyId = '11****TY'; // The AccessKey ID of your Alibaba Cloud account. For more information, see AccessKey pair. High security risks may arise if you use the AccessKey pair of your Alibaba Cloud account because the account has permissions to call all API operations. We recommend that you create and use a RAM user to call API operations or perform routine O&M. $accessKey = 'YT****ED'; // The AccessKey secret of your Alibaba Cloud account. $client = new Aliyun_Log_Client($endpoint, $accessKeyId, $accessKey); // Create Aliyun_Log_Client.
$req2 = new Aliyun_Log_Models_CreateLogstoreRequest(test-project,test-logstore,3,2); // Enter the project name, Logstore name, data retention period, and the number of shards. If you set ttl to 3650, data is permanently stored. $res2 = $client -> createLogstore($req2);