This topic describes how to get started with Log Service SDK for PHP and perform common operations.


Log Service SDK for PHP is installed. For more information, see Install Log Service SDK for PHP.

Sample code

  • Create a client for Log Service
    Aliyun_Log_Client is a PHP client that you can use to manage Log Service resources, such as projects and Logstores. Before you can use Log Service SDK for PHP to initiate a request, you must initialize a client instance.
    $endpoint = ''; // The Log Service endpoint. For more information, see Endpoints. In this example, the Log Service endpoint for the China (Hangzhou) region is used. Replace the parameter value with the actual endpoint. 
    $accessKeyId = '11****TY';        // The AccessKey ID of your Alibaba Cloud account. For more information, see AccessKey pair. An Alibaba Cloud account has permissions to call all API operations. If you use the AccessKey pair of an Alibaba Cloud account, security risks may occur. 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. 
  • Create a Logstore
    Log Service SDK for PHP provides a variety of sample code for your reference and use. The following sample code provides an example on how to create a Logstore:
    $req2 = new Aliyun_Log_Models_CreateLogstoreRequest(test-project,test-logstore,3,2);  // Specify the project name, Logstore name, data retention period, and number of shards. If you set the data retention period to 3650, data is permanently stored. 
    $res2 = $client -> createLogstore($req2);
    For more information about sample code, see aliyun-log-php-sdk.