tencentcloud/tencentcloud-cls-sdk-php

腾讯云 CLS 日志服务的 PHP SDK

v1.0.0 2022-04-22 04:03 UTC

This package is auto-updated.

Last update: 2024-08-27 09:45:13 UTC


README

SDK 发布时间

2022-04-20

简介

PHP 日志服务 SDK,用于将日志数据设置到腾讯云 CLS 日志服务。

API 参考

摘要

  1. 请求-请求风格的 Restful API 接口
  2. 使用协议缓冲区发送数据
  3. 发送到服务器时,数据可以 protobuf 压缩
  4. 如果发生任何错误,将抛出 TencentCloudLogException
  5. 引入简单的记录器,以不同级别轻松提交日志
  6. 创建本地日志缓存,以单个 HTTP POST 提交多个日志。

环境需求

  1. PHP 5.6.0 及以后版本:主分支

LZ4 压缩上传

1、暂不支持 LZ4 压缩上传

示例

<?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);