php -v
curl -sS https://getcomposer.org/installer | phpsudo mv composer.phar /usr/local/bin/composer
composer require tencentcloud/tencentcloud-cls-sdk-php
Variable | Type | Required | Description |
endpoint | String | Yes | |
accessKeyId | String | Yes | TencentCloud API key information. For key information acquisition, please visit API Key Management. Please ensure the associated account has appropriate SDK log upload permission. |
accessKey | String | Yes | TencentCloud API key information. For key information acquisition, please visit API Key Management. Please ensure the associated account has appropriate SDK log upload permission. |
topicId | String | Yes | Log topic ID info. |
token | String | No | Temporary key token. If needed, fill in this parameter to use a temporary key. For temporary key token retrieval, see Temporary Key. |
<?phprequire_once __DIR__ . '/vendor/autoload.php'; // Import Composer autoloaderuse TencentCloud\\Cls\\Models\\Request\\PutLogsRequest;use TencentCloud\\Cls\\Models\\LogItem;use TencentCloud\\Cls\\Client;use TencentCloud\\Cls\\TencentCloudLogException;function putLogs($client, $topicId) {$contents = array(//Set the log key and value content, the previous is the key, the following is the value'TestKey' => 'TestContent','test2' => 'helloworld');$logItem = new LogItem();$logItem->setTime(time()); // Set log time$logItem->setContents($contents); // Set log content$logItems = array($logItem); // Create log item array$request = new PutLogsRequest($topicId, null, $logItems); // Create requesttry {$response = $client->putLogs($request); // Send requestvar_dump($response->getRequestId()); // Output request ID} catch (TencentCloudLogException $ex) {var_dump($ex); // Capture and output Tencent Cloud log error} catch (Exception $ex) {var_dump($ex); // Capture and output other exceptions}}// Fill in the domain name, see the domain name in the API Log Upload Tab at the link: https://www.tencentcloud.com/document/product/614/18940?from_cn_redirect=1#.E5.9F.9F.E5.90.8D$endpoint = 'ap-xxxxxxxx.cls.tencentcs.com';// Fill in TencentCloud API key information. For key information acquisition, please visit: https://console.tencentcloud.com/cam/capi// Please ensure the associated account has log upload permissions. For the permission configuration guide, see: https://www.tencentcloud.com/document/product/614/68374?from_cn_redirect=1#.E4.BD.BF.E7.94.A8-api-.E4.B8.8A.E4.BC.A0.E6.95.B0.E6.8D.AE// This example retrieves from environmental variables. For the environment variable configuration guide, see: https://www.tencentcloud.com/document/product/614/113851?from_cn_redirect=1$accessKeyId = getenv('TENCENTCLOUD_SECRET_ID');$accessKey = getenv('TENCENTCLOUD_SECRET_KEY');// Set the topic ID for log upload, replace with your Topic ID$topicId = 'YOUR_TOPIC_ID';// Temporary key token, fill in if needed. Temporary key configuration guide: https://www.tencentcloud.com/document/product/614/87777?from_cn_redirect=1$token = "";// Create a client.$client = new Client($endpoint, $accessKeyId, $accessKey, $token);// Invoke function to send logsputLogs($client, $topicId);
Feedback