PHPackages                             sunsgne/rate-limit - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. sunsgne/rate-limit

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

sunsgne/rate-limit
==================

limit

1.1.2(3y ago)2151MITPHPPHP &gt;=7.4

Since May 18Pushed 2y ago1 watchersCompare

[ Source](https://github.com/sunsgneayo/webman-rateLimit)[ Packagist](https://packagist.org/packages/sunsgne/rate-limit)[ RSS](/packages/sunsgne-rate-limit/feed)WikiDiscussions main Synced 4w ago

READMEChangelogDependencies (4)Versions (15)Used By (0)

 [![sunsgne](https://camo.githubusercontent.com/e366b0a276ef18e50c689cb143c8f78eadfa2e14e8af4a8e9e1628362ad93f1e/68747470733a2f2f63646e2e6e696e65313132302e636e2f6c6f676f2d692e706e67)](https://camo.githubusercontent.com/e366b0a276ef18e50c689cb143c8f78eadfa2e14e8af4a8e9e1628362ad93f1e/68747470733a2f2f63646e2e6e696e65313132302e636e2f6c6f676f2d692e706e67)

**sunsgne/rate-limit**

**🐬 A PHP implementation of current limiting middleware for webman service HTTP-API 🐬**

[![Latest Stable Version](https://camo.githubusercontent.com/9dab5b9a29525b98c93a8fd5c0a4655d016c009916595e9b866d58f4dfbca404/687474703a2f2f706f7365722e707567782e6f72672f73756e73676e652f726174652d6c696d69742f76)](https://packagist.org/packages/sunsgne/rate-limit)[![Total Downloads](https://camo.githubusercontent.com/47ff190bdbb62c6332bc606635c0d00849024a1e1bc4e15e4a376747ee4c9645/687474703a2f2f706f7365722e707567782e6f72672f73756e73676e652f726174652d6c696d69742f646f776e6c6f616473)](https://packagist.org/packages/sunsgne/rate-limit)[![Latest Unstable Version](https://camo.githubusercontent.com/edfc7db1837590f514555268e6b294efd5baaa1a75faaaeeb02cc9da59cca785/687474703a2f2f706f7365722e707567782e6f72672f73756e73676e652f726174652d6c696d69742f762f756e737461626c65)](https://packagist.org/packages/sunsgne/rate-limit)[![License](https://camo.githubusercontent.com/cca47bd51d618fb6e0fd2c21579276d00c47caae5e422b4f58db3f12e5c8eec9/687474703a2f2f706f7365722e707567782e6f72672f73756e73676e652f726174652d6c696d69742f6c6963656e7365)](https://packagist.org/packages/sunsgne/rate-limit)[![PHP Version Require](https://camo.githubusercontent.com/f2f1c90406e94eff2d6d4841a30a13b9c406507b22295540d0bed0254c032e68/687474703a2f2f706f7365722e707567782e6f72672f73756e73676e652f726174652d6c696d69742f726571756972652f706870)](https://packagist.org/packages/sunsgne/rate-limit)

webman 服务限流
===========

[](#webman-服务限流)

> 基于illuminate/redis 的令牌桶限流中间件

安装
--

[](#安装)

```
composer require sunsgne/rate-limit
```

使用
--

[](#使用)

> 在 `webman`中使用

```
$moreRateLimit = Container::get(MoreRateLimitHandler::class);

$capacity       =  60;
$seconds        =  60;
$customerHandle = [
    'class'       => \support\Response::class,
    'constructor' => [
        429,
        array(),
        json_encode(['success' => false, 'msg' => '请求次数太频繁'], 256),
    ],
];

if (false === $moreRateLimit->handle(intval($capacity), intval($seconds))) {
    $newClass = $customerHandle['class'];
    return new $newClass(... \array_values($customerHandle['constructor']));
}
return $handler($request);
```

> 直接使用

```
$moreRateLimit = new \sunsgne\middleware\MoreRateLimit();
$capacity       =  60;
$seconds        =  60;
$customerHandle = [
    'class'       => \support\Response::class,
    'constructor' => [
        429,
        array(),
        json_encode(['success' => false, 'msg' => '请求次数太频繁'], 256),
    ],
];

if (false === $moreRateLimit->handle(intval($capacity), intval($seconds))) {
    $newClass = $customerHandle['class'];
    return new $newClass(... \array_values($customerHandle['constructor']));
}
```

### 参数示例

[](#参数示例)

参数名示例说明capacity60“桶”可以容纳的请求数seconds60“桶”完全重新装满所需的时间concurrencytrue开启并发限流cost1“桶”此操作使用的令牌数### 测试说明

[](#测试说明)

#### 不含数据库查询

[](#不含数据库查询)

> 进程数`24`,`moreRateLimit`,无业务逻辑

并发数平均值(ms)中位数(ms)最小值(ms)最大值(ms)吞吐量1011354215101.1100124124449428952.41000116002140032491643.0> 进程数`24`,`RateLimit`,无业务逻辑

并发数平均值(ms)中位数(ms)最小值(ms)最大值(ms)吞吐量1017.07611104.1100118154.0123983.41000118202359032401793.0#### 数据库查询

[](#数据库查询)

> 进程数`24`,`moreRateLimit`

并发数平均值(ms)中位数(ms)最小值(ms)最大值(ms)吞吐量1013513024101980.1> 进程数`24`,`RateLimit`

并发数平均值(ms)中位数(ms)最小值(ms)最大值(ms)吞吐量1012245110100470.1### 更新记录

[](#更新记录)

#### 1.1.3 - 2022-07-06

[](#113---2022-07-06)

##### 新增

[](#新增)

- redis 使用 `lua` 脚本加锁

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~4 days

Recently: every ~12 days

Total

14

Last Release

1403d ago

Major Versions

0.1.3 → 1.0.02022-05-18

### Community

Maintainers

![](https://www.gravatar.com/avatar/65843af70bae47cda80e0386c0640e2e17e1f8c8a12ea8fade3e1297237b26f3?d=identicon)[sunsgneayo](/maintainers/sunsgneayo)

---

Top Contributors

[![sunsgneayo](https://avatars.githubusercontent.com/u/51745500?v=4)](https://github.com/sunsgneayo "sunsgneayo (6 commits)")

---

Tags

middlewarephprate-limiting

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sunsgne-rate-limit/health.svg)

```
[![Health](https://phpackages.com/badges/sunsgne-rate-limit/health.svg)](https://phpackages.com/packages/sunsgne-rate-limit)
```

###  Alternatives

[infinum/eightshift-libs

WordPress libs developed by Eightshift team to use in modern WordPress.

63118.9k3](/packages/infinum-eightshift-libs)[drupal-code-builder/drupal-code-builder

Code generator for Drupal

27241.1k1](/packages/drupal-code-builder-drupal-code-builder)[php-di/zf1-bridge

Integrates PHP-DI to Zend Framework 1

27457.8k1](/packages/php-di-zf1-bridge)[sansec/composer-integrity-plugin

5624.2k1](/packages/sansec-composer-integrity-plugin)[php-di/symfony-bridge

Integrates PHP-DI to Symfony

17168.2k](/packages/php-di-symfony-bridge)[okapi/aop

PHP AOP is a PHP library that provides a powerful Aspect Oriented Programming (AOP) implementation for PHP.

3812.0k](/packages/okapi-aop)

PHPackages © 2026

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