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

ActiveLibrary[Caching](/categories/caching)

palepurple/rate-limit
=====================

PHP rate limiting library with Token Bucket Algorithm, originally touhonoob/rate-limit

3.0.3(1y ago)13555.7k↓56.8%2[1 issues](https://github.com/DavidGoodwin/RateLimit/issues)MITPHPPHP &gt;= 8.0CI failing

Since May 16Pushed 1y ago1 watchersCompare

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

READMEChangelog (3)Dependencies (10)Versions (16)Used By (0)

RateLimit
=========

[](#ratelimit)

[![GitHub Build](https://github.com/DavidGoodwin/RateLimit/actions/workflows/php.yml/badge.svg)](https://github.com/DavidGoodwin/RateLimit/actions/workflows/php.yml)

[![Coverage Status](https://camo.githubusercontent.com/7be50c0cf1dcae513b008a61bceb94e513755f807fa5557b9277882c2da69e21/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f4461766964476f6f6477696e2f526174654c696d69742f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/DavidGoodwin/RateLimit?branch=master)

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(['tcp://127.0.0.1:6379'])); // 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

47

—

FairBetter than 93% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity44

Moderate usage in the ecosystem

Community14

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor1

Top contributor holds 84.8% 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 ~274 days

Recently: every ~179 days

Total

14

Last Release

545d ago

Major Versions

1.3.0 → 2.0.02018-03-03

2.0.7 → 3.0.02024-10-20

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

1.3.0PHP &gt;=5.6

2.0.7PHP &gt;= 5.6

3.0.0PHP &gt;= 8.0

### Community

Maintainers

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

---

Top Contributors

[![DavidGoodwin](https://avatars.githubusercontent.com/u/203929?v=4)](https://github.com/DavidGoodwin "DavidGoodwin (134 commits)")[![touhonoob](https://avatars.githubusercontent.com/u/1391892?v=4)](https://github.com/touhonoob "touhonoob (20 commits)")[![ppeev0206](https://avatars.githubusercontent.com/u/76068993?v=4)](https://github.com/ppeev0206 "ppeev0206 (2 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)")

---

Tags

memcachedphpphp7predisrate-limiterrate-limitingredisstashphp

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[iazaran/smart-cache

Smart Cache is a caching optimization package designed to enhance the way your Laravel application handles data caching. It intelligently manages large data sets by compressing, chunking, or applying other optimization strategies to keep your application performant and efficient.

21114.2k](/packages/iazaran-smart-cache)[phpfastcache/phpssdb

PHP SSDB Driver for phpFastCache

14736.9k1](/packages/phpfastcache-phpssdb)[rapidwebltd/rw-file-cache

RW File Cache is a PHP File-based Caching Library. Its syntax is designed to closely resemble the PHP memcache extension.

15196.8k7](/packages/rapidwebltd-rw-file-cache)[yuzuru-s/redis-recommend

Wrapping Redis's sorted set APIs for specializing recommending operations.

392.9k](/packages/yuzuru-s-redis-recommend)[ichhabrecht/intcache

Turn uncachable page objects into cacheable links

193.9k](/packages/ichhabrecht-intcache)

PHPackages © 2026

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