PHPackages                             samescolas/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. samescolas/rate-limit

ActiveLibrary[Caching](/categories/caching)

samescolas/rate-limit
=====================

General purpose rate limiter implementation.

2.2.0(5y ago)08MITPHPPHP ^7.2 || ^8.0

Since Jan 22Pushed 5y agoCompare

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

READMEChangelogDependencies (7)Versions (11)Used By (0)

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

[](#rate-limit)

[![Build](https://github.com/samescolas/rate-limit/workflows/Build/badge.svg?branch=master)](https://github.com/samescolas/rate-limit/actions)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/d7a2b5647225fbc2285800624e5f2d4b9da6bb6daa9788655c0c7059e587f03c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f73616d6573636f6c61732f726174652d6c696d69742f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/samescolas/rate-limit/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/24a44dc418a490ec88e51d0fbd81e9b04bcd4a83ae19ba79a97900f19ee896bb/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f73616d6573636f6c61732f726174652d6c696d69742f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/samescolas/rate-limit/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/f82d84c81f9369d10a54b7314165e1ea646a8c6ba3c259fa75051e687f49a38f/68747470733a2f2f706f7365722e707567782e6f72672f73616d6573636f6c61732f726174652d6c696d69742f762f737461626c65)](https://packagist.org/packages/samescolas/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 samescolas/rate-limit
```

Usage
-----

[](#usage)

**Offensive rate limiting**

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

$rateLimiter = new RedisRateLimiter(new Redis());

$apiKey = 'abc123';

try {
    $rateLimiter->limit($apiKey, Rate::perMinute(100));

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

**Silent rate limiting**

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

$rateLimiter = new RedisRateLimiter(new Redis());

$ipAddress = '192.168.1.2';
$status = $rateLimiter->limitSilently($ipAddress, Rate::perMinute(100));

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

Credits
-------

[](#credits)

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

License
-------

[](#license)

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

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 84.3% 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 ~181 days

Recently: every ~357 days

Total

9

Last Release

1945d ago

Major Versions

0.4.0 → 1.0.02017-02-14

1.0.1 → 2.0.02020-03-22

PHP version history (3 changes)0.1.0PHP ^7.0

2.0.0PHP ^7.2

2.2.0PHP ^7.2 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/8d1746473ee72e71e20711c3947061aa1e2dd9cef27d45c92761ec4f6da66f2e?d=identicon)[samescolas](/maintainers/samescolas)

---

Top Contributors

[![nikolaposa](https://avatars.githubusercontent.com/u/6012807?v=4)](https://github.com/nikolaposa "nikolaposa (134 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)")[![samescolas](https://avatars.githubusercontent.com/u/16058877?v=4)](https://github.com/samescolas "samescolas (3 commits)")[![poursal](https://avatars.githubusercontent.com/u/1989397?v=4)](https://github.com/poursal "poursal (2 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

redisrate limit

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[predis/predis

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

7.8k305.7M2.4k](/packages/predis-predis)[nikolaposa/rate-limit

General purpose rate limiter implementation.

2711.5M3](/packages/nikolaposa-rate-limit)[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.

5311.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.

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

PHPackages © 2026

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