PHP code example of tencentcloud / tencentcloud-cls-sdk-php

1. Go to this page and download the library: Download tencentcloud/tencentcloud-cls-sdk-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tencentcloud / tencentcloud-cls-sdk-php example snippets




encentCloud\Cls\Models\Request\PutLogsRequest;
use TencentCloud\Cls\Models\LogItem;
use TencentCloud\Cls\Client;
use TencentCloud\Cls\TencentCloudLogException;



function putLogs($client, $topicId) {
    $contents = array(
        'TestKey'=>'TestContent',
        'test2'=>'beijing'
    );
    $logItem = new LogItem();
    $logItem->setTime(time());
    $logItem->setContents($contents);
    $logItems = array($logItem);
    $request = new PutLogsRequest($topicId, null, $logItems);

    try {
        $response = $client->putLogs($request);
        var_dump($response->getRequestId());
    } catch (TencentCloudLogException $ex) {
        var_dump($ex);
    } catch (Exception $ex) {
        var_dump($ex);
    }
}

$endpoint = 'ap-guangzhou.cls.tencentcs.com';
$accessKeyId = '';
$accessKey = '';
$topicId = '';
$token = "";


$client = new Client($endpoint, $accessKeyId, $accessKey,$token);
putLogs($client, $topicId);