tencentcloud / tencentcloud-cls-sdk-php
The Php SDK of Tencent Cloud CLS log service
v1.0.0
2022-04-22 04:03 UTC
Requires
- php: >=5.6.0
- ext-json: *
- google/protobuf: ^3.20
README
SDK RELEASE TIME
2022-04-20
Introduction
Log Service SDK for PHP,used to set log data to TencentCloud CLS Log Service.
API Reference:
Summary
- Request-Request style Restful API interface
- Use Protocol buffer to send data
- Data can be protobuf compressed when sending to server
- TencentCloudLogException will be thrown if any error happen
- Introduce simple logger for submit log easily with different levels
- Create local log cache to submit several logs in single http post.
Environment Requirement
- PHP 5.6.0 and later:Master Branch
LZ4 压缩上传
1、暂不支持LZ4 压缩上传
密钥信息
accessKeyId和accessKey为云API密钥,密钥信息获取请前往密钥获取。并请确保云API密钥关联的账号具有相应的SDK上传日志权限
Demo
<?php
require_once __DIR__.'../../vendor/autoload.php';
use TencentCloud\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);