PHPackages                             wendy/aliyun-sls-api - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. wendy/aliyun-sls-api

ActiveLibrary

wendy/aliyun-sls-api
====================

The SLS SDK for Aliyun OpenAPI

1.0(6y ago)07MITPHPPHP &gt;=5.3.0CI failing

Since Dec 27Pushed 6y ago1 watchersCompare

[ Source](https://github.com/wendy-rose/aliyun-sls-api)[ Packagist](https://packagist.org/packages/wendy/aliyun-sls-api)[ Docs](https://github.com/wendy-rose/aliyun-sls-api.git)[ RSS](/packages/wendy-aliyun-sls-api/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (2)Versions (2)Used By (0)

阿里云日志开放API
==========

[](#阿里云日志开放api)

此包来源lokielse/aliyun-open-api-sls，在此基础上修复了bug

Install
-------

[](#install)

Via Composer

```
$ composer require wendy/aliyun-open-api-sls
```

Usage
-----

[](#usage)

```
/**
 * Config
 */
$config = [
	'AccessKeyId'     => 'your_access_key_id',
	'AccessKeySecret' => 'your_access_key_secret',
	'endpoint'        => 'cn-hangzhou.sls.aliyuncs.com',
	'project'         => 'your_sls_project_name',
	'logStore'        => 'your_sls_log_store_name',
	'topic'           => '',
	'source'          => '',
];

/**
 * 写日志 (Write Logs)
 */
$logs = array(
	new LogItem([ 'user' => 'jello', 'action' => 'trash_photo', 'object_id' => 123456 ]),
	new LogItem([ 'user' => 'frank', 'action' => 'delete_user', 'object_id' => 100236 ]),
);

$putLogsRequest  = new PutLogsRequest($config['project'], $config['logStore'], $config['topic'], $config['source'], $logs);
$client          = new Client($config['endpoint'], $config['AccessKeyId'], $config['AccessKeySecret']);
$putLogsResponse = $client->putLogs($putLogsRequest);

/**
 * 读日志  (Read Logs)
 * 在控制台查看日志有3-5分钟延迟, 但是使用该SDK查看无延迟
 */
$listShardRequest = new ListShardsRequest($config['project'], $config['logStore']);

$listShardResponse = $client->listShards($listShardRequest);

foreach ($listShardResponse->getShardIds() as $shardId) {
	/**
	 * 对每一个ShardId，先获取Cursor
	 */
	$getCursorRequest = new GetCursorRequest($config['project'], $config['logStore'], $shardId, null, time() - 60);
	$response         = $client->getCursor($getCursorRequest);
	$cursor           = $response->getCursor();
	$count            = 100;

	while (true) {
		/**
		 * 从cursor开始读数据
		 */
		$batchGetDataRequest = new BatchGetLogsRequest($config['project'], $config['logStore'], $shardId, $count, $cursor);

		var_dump($batchGetDataRequest);

		$response = $client->batchGetLogs($batchGetDataRequest);

		if ($cursor == $response->getNextCursor()) {
			break;
		}

		$logGroupList = $response->getLogGroupList();

		/**
		 * @var \Aliyun\SLS\Log\LogGroup  $logGroup
		 * @var Aliyun\SLS\Log\Log        $log
		 * @var Aliyun\SLS\Log\LogContent $content
		 */
		foreach ($logGroupList as $logGroup) {

			print ( $logGroup->getCategory() );

			foreach ($logGroup->getLogsArray() as $log) {
				foreach ($log->getContentsArray() as $content) {
					print( $content->getKey() . ":" . $content->getValue() . "\t" );
				}
				print( "\n" );
			}
		}
		$cursor = $response->getNextCursor();
	}
}
```

[官方文档](https://help.aliyun.com/document_detail/29074.html)

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2327d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/bc07fd0de2ef7131df5925468390d0e7bb5c187c55cc419dec48cbf1c17c15a6?d=identicon)[wendy](/maintainers/wendy)

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/wendy-aliyun-sls-api/health.svg)

```
[![Health](https://phpackages.com/badges/wendy-aliyun-sls-api/health.svg)](https://phpackages.com/packages/wendy-aliyun-sls-api)
```

###  Alternatives

[lokielse/aliyun-open-api-sls

The SLS SDK for Aliyun OpenAPI

1060.5k15](/packages/lokielse-aliyun-open-api-sls)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
