PHPackages                             nikolaposa/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. [Caching](/categories/caching)
4. /
5. nikolaposa/rate-limit

ActiveLibrary[Caching](/categories/caching)

nikolaposa/rate-limit
=====================

General purpose rate limiter implementation.

3.2.0(2y ago)2711.5M—3.1%48[5 issues](https://github.com/nikolaposa/rate-limit/issues)[1 PRs](https://github.com/nikolaposa/rate-limit/pulls)3MITPHPPHP ^8.1

Since Jan 22Pushed 1y ago13 watchersCompare

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

READMEChangelog (10)Dependencies (7)Versions (19)Used By (3)

Rate Limit
==========

[](#rate-limit)

[![Build](https://github.com/nikolaposa/rate-limit/workflows/Build/badge.svg?branch=master)](https://github.com/nikolaposa/rate-limit/actions)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/dded84f090ccbbfe83fc725d9c77ecd2b345a25a0f8cf0397a46794e5a9dba57/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6e696b6f6c61706f73612f726174652d6c696d69742f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/nikolaposa/rate-limit/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/38fdcbcbe315a76331dfe37b152680fab31a87fb08d3d2005a92d88e5c0b8d2d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6e696b6f6c61706f73612f726174652d6c696d69742f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/nikolaposa/rate-limit/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/4dcc1280d5115a30a11bec2e9f555f568edb6d36a818e361f18e8972e2d50ed5/68747470733a2f2f706f7365722e707567782e6f72672f6e696b6f6c61706f73612f726174652d6c696d69742f762f737461626c65)](https://packagist.org/packages/nikolaposa/rate-limit)[![PDS Skeleton](https://camo.githubusercontent.com/a8ce1f2a7b71f101b18fc0393ba5bf89b7a5b1f9d08a31b658ca0eab0064c0f6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7064732d736b656c65746f6e2d626c75652e737667)](https://github.com/php-pds/skeleton)

General purpose rate limiter that can be used to limit the rate at which certain operation can be performed. Default implementation uses Redis as backend.

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

[](#installation)

The preferred method of installation is via [Composer](http://getcomposer.org/). Run the following command to install the latest version of a package and add it to your project's `composer.json`:

```
composer require nikolaposa/rate-limit
```

Usage
-----

[](#usage)

**Terminating rate limiter**

```
use RateLimit\Exception\LimitExceeded;
use RateLimit\Rate;
use RateLimit\RedisRateLimiter;
use Redis;

$rateLimiter = new RedisRateLimiter(Rate::perMinute(100), new Redis());

$apiKey = 'abc123';

try {
    $rateLimiter->limit($apiKey);

    //on success
} catch (LimitExceeded $exception) {
   //on limit exceeded
}
```

**Silent rate limiter**

```
use RateLimit\Rate;
use RateLimit\RedisRateLimiter;
use Redis;

$rateLimiter = new RedisRateLimiter(Rate::perMinute(100), new Redis());

$ipAddress = '192.168.1.2';
$status = $rateLimiter->limitSilently($ipAddress);

echo $status->getRemainingAttempts(); //99
```

**Practical usage with configuring multiple rate limiting strategies in a project**

```
use RateLimit\Rate;
use RateLimit\RedisRateLimiter;

$container->set('rate_limiter.api', new RedisRateLimiter(Rate::perSecond(10), $container->get('redis')));
$container->set('rate_limiter.videos', new RedisRateLimiter(Rate::perDay(5), $container->get('redis')));
```

Supported drivers
-----------------

[](#supported-drivers)

- [Redis](src/RedisRateLimiter.php)
- [Predis](src/PredisRateLimiter.php)
- [Memcached](src/MemcachedRateLimiter.php)
- [APCu](src/ApcuRateLimiter.php)
- [In-memory](src/InMemoryRateLimiter.php)

Credits
-------

[](#credits)

- [Nikola Poša](https://github.com/nikolaposa)
- [All Contributors](../../contributors)

License
-------

[](#license)

Released under MIT License - see the [License File](LICENSE) for details.

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance26

Infrequent updates — may be unmaintained

Popularity59

Moderate usage in the ecosystem

Community28

Small or concentrated contributor base

Maturity80

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 86.9% 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 ~222 days

Recently: every ~304 days

Total

13

Last Release

731d ago

Major Versions

0.4.0 → 1.0.02017-02-14

1.0.1 → 2.0.02020-03-22

2.2.x-dev → 3.0.02021-10-31

PHP version history (5 changes)0.1.0PHP ^7.0

2.0.0PHP ^7.2

2.2.0PHP ^7.2 || ^8.0

3.0.0PHP ^7.4 || ^8.0

3.1.0PHP ^8.1

### Community

Maintainers

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

---

Top Contributors

[![nikolaposa](https://avatars.githubusercontent.com/u/6012807?v=4)](https://github.com/nikolaposa "nikolaposa (152 commits)")[![juliangut](https://avatars.githubusercontent.com/u/1104131?v=4)](https://github.com/juliangut "juliangut (10 commits)")[![localheinz](https://avatars.githubusercontent.com/u/605483?v=4)](https://github.com/localheinz "localheinz (8 commits)")[![poursal](https://avatars.githubusercontent.com/u/1989397?v=4)](https://github.com/poursal "poursal (2 commits)")[![deiga](https://avatars.githubusercontent.com/u/27202?v=4)](https://github.com/deiga "deiga (1 commits)")[![fxm5547](https://avatars.githubusercontent.com/u/6702775?v=4)](https://github.com/fxm5547 "fxm5547 (1 commits)")[![virtualize](https://avatars.githubusercontent.com/u/220102?v=4)](https://github.com/virtualize "virtualize (1 commits)")

---

Tags

rate-limitrate-limitingredisredisrate limit

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[predis/predis

A flexible and feature-complete Redis/Valkey client for PHP.

7.8k305.7M2.4k](/packages/predis-predis)[snc/redis-bundle

A Redis bundle for Symfony

1.0k39.4M67](/packages/snc-redis-bundle)[clue/redis-protocol

A streaming Redis protocol (RESP) parser and serializer written in pure PHP.

5211.0M13](/packages/clue-redis-protocol)[rtcamp/nginx-helper

Cleans nginx's fastcgi/proxy cache or redis-cache whenever a post is edited/published. Also provides cloudflare edge cache purging with Cache-Tags.

23517.0k1](/packages/rtcamp-nginx-helper)

PHPackages © 2026

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