PHPackages                             goodjun/aliyun-open-api-sls - 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. goodjun/aliyun-open-api-sls

ActiveLibrary

goodjun/aliyun-open-api-sls
===========================

The SLS SDK for Aliyun OpenAPI

v1.1.1(2y ago)17121MITPHPPHP &gt;=5.3.0

Since Jul 22Pushed 2y agoCompare

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

READMEChangelog (1)Dependencies (2)Versions (6)Used By (1)

The SLS SDK for Aliyun OpenAPI
==============================

[](#the-sls-sdk-for-aliyun-openapi)

[![Latest Version on Packagist](https://camo.githubusercontent.com/aaebf95dc928e6ca513dc7e4d057e613ceaecb1ba29fb685f0c343013b23f2b3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f676f6f646a756e2f616c6979756e2d6f70656e2d6170692d736c732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/goodjun/aliyun-open-api-sls)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Total Downloads](https://camo.githubusercontent.com/0d87a967be6eb929cbf9d27a055ab4cd279e335ccdfbfb34903ebc68ecce0fbb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f676f6f646a756e2f616c6979756e2d6f70656e2d6170692d736c732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/goodjun/aliyun-open-api-sls)

The SLS SDK for Aliyun OpenAPI

Authorship
==========

[](#authorship)

This started as a fork from

Install
-------

[](#install)

Via Composer

```
$ composer require goodjun/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)

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Lokielse](https://github.com/goodjun)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 70% of commits — single point of failure

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

Every ~1270 days

Total

3

Last Release

1037d ago

### Community

Maintainers

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

---

Top Contributors

[![goodjun](https://avatars.githubusercontent.com/u/18377597?v=4)](https://github.com/goodjun "goodjun (7 commits)")[![lokielse](https://avatars.githubusercontent.com/u/1573211?v=4)](https://github.com/lokielse "lokielse (3 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  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)
