PHPackages                             thamtech/yii2-ratelimiter-advanced - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. thamtech/yii2-ratelimiter-advanced

ActiveYii2-extension[HTTP &amp; Networking](/categories/http)

thamtech/yii2-ratelimiter-advanced
==================================

An advanced request rate limiter

0.5(5y ago)41273.1k↓37.9%2[4 issues](https://github.com/thamtech/yii2-ratelimiter-advanced/issues)[1 PRs](https://github.com/thamtech/yii2-ratelimiter-advanced/pulls)2BSD-3-ClausePHPPHP &gt;=5.6.0

Since May 31Pushed 5y ago2 watchersCompare

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

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

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

[](#yii2-advanced-rate-limiter)

Advanced Rate Limiter is a [Yii2's](http://www.yiiframework.com) filter to enforce or monitor request rate limits.

In contrast to Yii2's built-in [RateLimiter](http://www.yiiframework.com/doc-2.0/guide-rest-rate-limiting.html), Advanced Rate Limiter:

- allows you to define multiple, independent rate limit definitions
    - by controller action, and
    - by an identifier such as an IP address, user ID, other identifiers relevant to your application, or a combination thereof;
- provides support for customizing the type of response to a checked or exceeded rate limit such as:
    - sending a `429 Too Many Requests` HTTP response,
    - triggering a Yii2 [Event](http://www.yiiframework.com/doc-2.0/guide-concept-events.html),
    - setting rate-limit HTTP headers, and/or
    - executing your own [Callable](http://php.net/manual/en/language.types.callable.php) or [anonymous function](http://php.net/manual/en/functions.anonymous.php);
- provides support for storing and managing the `allowance` and `timestamp`values for each rate limit (Yii2's built-in RateLimiter requires you to implement the storage yourself);
- allows you to customize the prefix of rate-limit HTTP headers instead of the hardcoded `X-Rate-Limit-` prefix used by the built-in `RateLimiter`;
- provides support for sending the `Retry-After` HTTP header indicating how many seconds the client should wait before retrying.

For license information check the [LICENSE](LICENSE.md)-file.

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

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

```
php composer.phar require --prefer-dist thamtech/yii2-ratelimiter-advanced

```

or add

```
"thamtech/yii2-ratelimiter-advanced": "*"

```

to the `require` section of your `composer.json` file.

Usage
-----

[](#usage)

### Introduction

[](#introduction)

This Rate Limiter is an implementation of the [leaky bucket algorithm](http://en.wikipedia.org/wiki/Leaky_bucket).

In general, you will configure the rate limiter as a behavior on any Controller class you want to rate limit. For example,

```
