PHPackages                             touhonoob/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. touhonoob/rate-limit

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

touhonoob/rate-limit
====================

PHP rate limiting library with Token Bucket Algorithm

2.0.2(7y ago)137520.0k↓21.6%26[1 PRs](https://github.com/touhonoob/RateLimit/pulls)2MITPHPPHP &gt;=5.6

Since May 16Pushed 3y ago4 watchersCompare

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

READMEChangelog (3)Dependencies (7)Versions (8)Used By (2)

RateLimit
=========

[](#ratelimit)

[![Build Status](https://camo.githubusercontent.com/41d4420edf3bb6dee6f0fc678cc51cee02c01371b946a1816a888a1e6ea7ed2c/68747470733a2f2f7472617669732d63692e6f72672f4461766964476f6f6477696e2f526174654c696d69742e737667)](https://travis-ci.org/DavidGoodwin/RateLimit/)

PHP Rate Limiting Library With Token Bucket Algorithm with minimal external dependencies.

Installation
============

[](#installation)

`composer require palepurple/rate-limit`

Storage Adapters
================

[](#storage-adapters)

The RateLimiter needs to know where to get/set data.

Depending on which adapter you install, you may need to install additional libraries (predis/predis or tedivm/stash) or PHP extensions (e.g. Redis, Memcache, APC)

- [APCu](https://pecl.php.net/package/APCu)
- [Redis](https://pecl.php.net/package/redis) or [Predis](https://github.com/nrk/predis)
- [Stash](http://www.stashphp.com) (This supports many drivers - see  )
- [Memcached](http://php.net/manual/en/intro.memcached.php)

Example
=======

[](#example)

```
require 'vendor/autoload.php';

use \PalePurple\RateLimit\RateLimit;
use \PalePurple\RateLimit\Adapter\APC as APCAdapter;
use \PalePurple\RateLimit\Adapter\Redis as RedisAdapter;
use \PalePurple\RateLimit\Adapter\Predis as PredisAdapter;
use \PalePurple\RateLimit\Adapter\Memcached as MemcachedAdapter;
use \PalePurple\RateLimit\Adapter\Stash as StashAdapter;

$adapter = new APCAdapter(); // Use APC as Storage
// Alternatives:
//
// $adapter = new RedisAdapter((new \Redis()->connect('localhost'))); // Use Redis as Storage
//
// $adapter = new PredisAdapter((new \Predis\Predis())->connect('localhost')); // Use Predis as Storage
//
// $memcache = new \Memcached();
// $memcache->addServer('localhost', 11211);
// $adapter = new MemcacheAdapter($memcache);
//
// $stash = new \Stash\Pool(new \Stash\Driver\FileSystem());
// $adapter = new StashAdapter($stash);

$rateLimit = new RateLimit("myratelimit", 100, 3600, $adapter); // 100 Requests / Hour

$id = $_SERVER['REMOTE_ADDR']; // Use client IP as identity
if ($rateLimit->check($id)) {
  echo "passed";
} else {
  echo "rate limit exceeded";
}
```

Installing via Composer
=======================

[](#installing-via-composer)

```
curl -sS https://getcomposer.org/installer | php
composer.phar require palepurple/rate-limit
```

References
==========

[](#references)

- [stackoverflow post about Rate Limiting](http://stackoverflow.com/a/668327/670662)
- [wikipedia token bucket](http://en.wikipedia.org/wiki/Token_bucket)
- [this code is forked from here...](https://github.com/touhonoob/RateLimit)

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity53

Moderate usage in the ecosystem

Community22

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 73.6% 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 ~470 days

Total

4

Last Release

2609d ago

Major Versions

1.2.0 → 2.0.22019-03-27

PHP version history (2 changes)1.2.0PHP &gt;=5.5

2.0.2PHP &gt;=5.6

### Community

Maintainers

![](https://www.gravatar.com/avatar/2444f402d934bef19b4c8adabd1547b157c91e8de7e7e08d846e10ae42761a52?d=identicon)[touhonoob](/maintainers/touhonoob)

---

Top Contributors

[![DavidGoodwin](https://avatars.githubusercontent.com/u/203929?v=4)](https://github.com/DavidGoodwin "DavidGoodwin (64 commits)")[![touhonoob](https://avatars.githubusercontent.com/u/1391892?v=4)](https://github.com/touhonoob "touhonoob (21 commits)")[![bitbybit](https://avatars.githubusercontent.com/u/1628191?v=4)](https://github.com/bitbybit "bitbybit (1 commits)")[![Icewild](https://avatars.githubusercontent.com/u/8243173?v=4)](https://github.com/Icewild "Icewild (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

PHPackages © 2026

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