PHPackages                             yunwuxin/think-throttle - 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. yunwuxin/think-throttle

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

yunwuxin/think-throttle
=======================

Throttle is a rate limiter for thinkphp6

v1.0.1(2y ago)362Apache-2.0PHP

Since Jan 8Pushed 2y ago1 watchersCompare

[ Source](https://github.com/yunwuxin/think-throttle)[ Packagist](https://packagist.org/packages/yunwuxin/think-throttle)[ RSS](/packages/yunwuxin-think-throttle/feed)WikiDiscussions master Synced yesterday

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

安装
--

[](#安装)

```
composer require yunwuxin/think-throttle

```

> 下面示例均为限制每分钟允许10次访问

使用方式
----

[](#使用方式)

### 门面方式

[](#门面方式)

```
//...
use yunwuxin\throttle\facade\RateLimiter;

//...

$key = 'xxxx';

if(RateLimiter::tooManyAttempts($key, 10))
{
    //超出频率限制了
    throw new \Exception('....');
}

RateLimiter::hit($key, 60);

//....其他操作
```

### 依赖注入方式

[](#依赖注入方式)

```
use yunwuxin\throttle\RateLimiter;

class SomeClass
{

    public function index(Ratelimiter $limiter)
    {
        $key = 'xxxx';

        if($limiter->tooManyAttempts($key, 10))
        {
            //超出频率限制了
            throw new \Exception('....');
        }

        $limiter->hit($key, 60);

        //....其他操作
    }
}
```

### 中间件方式

[](#中间件方式)

```
use yunwuxin\throttle\middleware\ThrottleRequests;
use think\facade\Route;

Route::group(function(){
    //路由注册

})->middleware(ThrottleRequests::class, 10);
```

中间件支持3个参数 `$maxAttempts`, `$decayMinutes`, `$prefix`

```
...->middleware(ThrottleRequests::class, $maxAttempts, $decayMinutes, $prefix);

```

`$maxAttempts`: 可访问次数，默认值60
`$decayMinutes`: 单位时间，默认值1分钟
`$prefix`: $key的前缀，默认值为空,可以传入一个闭包，返回一个字符串作为$key，该闭包支持依赖注入

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

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 ~1355 days

Total

2

Last Release

961d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7422243107bba2d58c5682b69d1c405e66fa027df2f6202afc1bb0c55559a7b1?d=identicon)[yunwuxin](/maintainers/yunwuxin)

---

Top Contributors

[![yunwuxin](https://avatars.githubusercontent.com/u/2168125?v=4)](https://github.com/yunwuxin "yunwuxin (2 commits)")

### Embed Badge

![Health badge](/badges/yunwuxin-think-throttle/health.svg)

```
[![Health](https://phpackages.com/badges/yunwuxin-think-throttle/health.svg)](https://phpackages.com/packages/yunwuxin-think-throttle)
```

###  Alternatives

[ashallendesign/short-url

A Laravel package for creating shortened URLs for your web apps.

1.4k1.9M4](/packages/ashallendesign-short-url)[intervention/zodiac

Zodiac Sign Calculator

58191.7k](/packages/intervention-zodiac)[erlandmuchasaj/laravel-gzip

Gzip your responses.

40129.3k2](/packages/erlandmuchasaj-laravel-gzip)[solspace/craft-calendar

The most powerful event management and calendaring plugin!

1830.8k1](/packages/solspace-craft-calendar)

PHPackages © 2026

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