PHPackages                             razonyang/yii2-rate-limiter - 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. razonyang/yii2-rate-limiter

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

razonyang/yii2-rate-limiter
===========================

Yii2 Rate Limiter

1.0.0(6y ago)1025.0k↓48.1%1BSD-3-ClausePHPPHP ^7.1

Since Aug 21Pushed 6y ago2 watchersCompare

[ Source](https://github.com/razonyang/yii2-rate-limiter)[ Packagist](https://packagist.org/packages/razonyang/yii2-rate-limiter)[ RSS](/packages/razonyang-yii2-rate-limiter/feed)WikiDiscussions master Synced 1mo ago

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

Yii2 Rate Limiter
=================

[](#yii2-rate-limiter)

[![Build Status](https://camo.githubusercontent.com/534f8a6933a88270235f90b5a0ee6c37f67aa9aed65cf6a61cdcd6e82d9a7c5a/68747470733a2f2f7472617669732d63692e6f72672f72617a6f6e79616e672f796969322d726174652d6c696d697465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/razonyang/yii2-rate-limiter)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/597373d72424fbeb322a330fc809cc1eeb400020ab6c424b744f449095834a39/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f72617a6f6e79616e672f796969322d726174652d6c696d697465722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/razonyang/yii2-rate-limiter/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/55a6047e3bf51e0dc556e0c0209cd9e7fcca9e27c15e98e80fdf8117c180a6c8/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f72617a6f6e79616e672f796969322d726174652d6c696d697465722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/razonyang/yii2-rate-limiter/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/92fdb59f9c71065fdbfffe98e81f7a611b18149df83e4f4a4f68d3e77d458a99/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72617a6f6e79616e672f796969322d726174652d6c696d697465722e737667)](https://packagist.org/packages/razonyang/yii2-rate-limiter)[![Total Downloads](https://camo.githubusercontent.com/209c750fe60c84e5019612b0984e43ba7e62b8b72d60b1440490dfe6eb4fda90/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f72617a6f6e79616e672f796969322d726174652d6c696d697465722e737667)](https://packagist.org/packages/razonyang/yii2-rate-limiter)[![LICENSE](https://camo.githubusercontent.com/8781d8b8a1871ede99b78c2dbeb541ab043fba72ab2dadcae9afda80472275e7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f72617a6f6e79616e672f796969322d726174652d6c696d69746572)](LICENSE)

Backends
--------

[](#backends)

- `Memcached` requires [memcached](https://www.php.net/manual/en/book.memcached.php) extension.
- `Redis` requires [redis](https://github.com/phpredis/phpredis) extension or [yiisoft/yii2-redis](https://github.com/yiisoft/yii2-redis) package.

Installation
------------

[](#installation)

```
composer require razonyang/yii2-rate-limiter

```

Usage
-----

[](#usage)

Let's take 5000 requests every hours as example:

```
return [
    public function behaviors()
    {
        return [
            // redis via redis extension
            'rateLimiter' => [
                'class' => \RazonYang\Yii2\RateLimiter\RedisRateLimiter::class,
                'password' => '',
                'hostname' => 'localhost',
                'port' => 6379,
                'capacity' => 5000,
                'rate' => 0.72,
                'limitPeriod' => 3600,
                'prefix' => 'rate_limiter:',
                'ttl' => 3600,
                // 'nameCallback' => $callback,
            ],
            // redis via yii2-redis
            'rateLimiter' => [
                'class' => \RazonYang\Yii2\RateLimiter\Redis\RateLimiter::class,
                'redis' => 'redis', // redis component name or definition
                'capacity' => 5000,
                'rate' => 0.72,
                'limitPeriod' => 3600,
                'prefix' => 'rate_limiter:',
                'ttl' => 3600,
                // 'nameCallback' => $callback,
            ],

            // memcached
            'rateLimiter' => [
                'class' => \RazonYang\Yii2\RateLimiter\MemcachedRateLimiter::class,
                'hostname' => 'localhost',
                'port' => 11211,
                'capacity' => 5000,
                'rate' => 0.72,
                'limitPeriod' => 3600,
                'prefix' => 'rate_limiter:',
                'ttl' => 3600,
                // 'nameCallback' => $callback,
            ],
        ];
    }
];
```

`RateLimiter` takes `uid:route`(authorized) or `ip:route`(guest) as bucket name, you can also change this behavior via `nameCallback`:

```
$nameCallback = function (
    \yii\web\User $user,
    \yii\web\Request $request,
    \yii\base\Action $action
): string {
    return 'bucket name';
}
```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity53

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

Unknown

Total

1

Last Release

2463d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/17720932?v=4)[Razon Yang](/maintainers/RazonYang)[@razonyang](https://github.com/razonyang)

---

Top Contributors

[![razonyang](https://avatars.githubusercontent.com/u/17720932?v=4)](https://github.com/razonyang "razonyang (1 commits)")

---

Tags

rate-limiteryii2

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/razonyang-yii2-rate-limiter/health.svg)

```
[![Health](https://phpackages.com/badges/razonyang-yii2-rate-limiter/health.svg)](https://phpackages.com/packages/razonyang-yii2-rate-limiter)
```

###  Alternatives

[dmstr/yii2-cookie-consent

Yii2 Cookie Consent Widget

1452.6k](/packages/dmstr-yii2-cookie-consent)[richardfan1126/yii2-js-register

Yii2 widget to register JS into view

1357.2k7](/packages/richardfan1126-yii2-js-register)

PHPackages © 2026

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