PHP code example of le2le / aliyun-log

1. Go to this page and download the library: Download le2le/aliyun-log 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/ */

    

le2le / aliyun-log example snippets



$endpoint= 'http://cn-shenzhen.log.aliyuncs.com';
$accessKeyId = '1';
$accessKey = '2';
$project = '3';
$logstore = '4';
$token= '';
$client = new Le2le\AliyunLog\Client($endpoint, $accessKeyId, $accessKey,$token);

$topic = 'TestTopic';

$array = [['342423']];
$logitems = [];
foreach ($array as $one)
{
$logItem = new \Le2le\AliyunLog\Models\LogItem();
$logItem->setTime(time());
$logItem->setContents($one);
$logitems[] = $logItem;
}

$request = new Le2le\AliyunLog\Models\Request\PutLogsRequest($project, $logstore,
$topic, null, $logitems);

$response = '';
try {
$response = $client->putLogs($request);
} catch (Le2le\AliyunLog\Exception $ex) {

var_dump($ex);
} catch (\Exception $ex) {

var_dump($ex);
}

var_dump($response);