PHPackages                             razonyang/psr-rate-limiter - 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. razonyang/psr-rate-limiter

ActiveLibrary

razonyang/psr-rate-limiter
==========================

PSR-15 Rate Limiter Middleware

1.0.0(6y ago)5123BSD-3-ClausePHP

Since Aug 21Pushed 6y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (5)Versions (2)Used By (0)

PSR Rate Limiter Middleware
===========================

[](#psr-rate-limiter-middleware)

[![Build Status](https://camo.githubusercontent.com/1e348afd644dd3d52eff19130af7008c45b75234000177afe986f849c814c601/68747470733a2f2f7472617669732d63692e6f72672f72617a6f6e79616e672f7073722d726174652d6c696d697465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/razonyang/psr-rate-limiter)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/4b08a2cb934abed9740a67b06809bbdfd77e748fba4867492b620f09370e8f3f/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f72617a6f6e79616e672f7073722d726174652d6c696d697465722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/razonyang/psr-rate-limiter/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/6e4838bff93188c865baa2edeca98685845451a4ab363cd0342bf83cba6208e4/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f72617a6f6e79616e672f7073722d726174652d6c696d697465722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/razonyang/psr-rate-limiter/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/6b42c54e8c929d1ef8aefda4777d9a8fb5492787beac7bd1b74e8eb15bae346d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72617a6f6e79616e672f7073722d726174652d6c696d697465722e737667)](https://packagist.org/packages/razonyang/psr-rate-limiter)[![Total Downloads](https://camo.githubusercontent.com/327d32dbaeb94475d13d70f3cee2a8ff88911d6e716f865b8c96561e9c10f4c8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f72617a6f6e79616e672f7073722d726174652d6c696d697465722e737667)](https://packagist.org/packages/razonyang/psr-rate-limiter)[![LICENSE](https://camo.githubusercontent.com/d168b3106f1c77039bc2cff23b5160ad27870ed6daad3c5d4580d726bcc35f4a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f72617a6f6e79616e672f7073722d726174652d6c696d69746572)](LICENSE)

It was built on top of [Token Bucket](https://github.com/razonyang/php-token-bucket).

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

[](#installation)

```
composer require razonyang/psr-rate-limiter

```

Usage
-----

[](#usage)

Let's take 5000 requests every hours as example:

```
// creates a token bucket manager, redis or memcached(built-in)
$capacity = 5000; // each bucket capacity, in other words, maximum number of tokens.
$rate = 0.72; // 3600/5200, how offen the token will be added to bucket
$logger = new \Psr\Log\NullLogger(); // PSR logger
$ttl = 3600; // time to live.
$prefix = 'rateLimiter:'; // prefix.
$manager = new \RazonYang\TokenBucket\Manager\RedisManager($capacity, $rate, $logger, $redis, $ttl, $prefix);

// PSR HTTP response factory
$responseFactory = new \Nyholm\Psr7\Factory\Psr17Factory();

// bucket name callback, let's we treat ip:path as bucket name here
$nameCallback = function (\Psr\Http\Message\ServerRequestInterface $request): string {
    $parameters = $request->getServerParams();
    $path = '';
    $ipKeys = ['HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP', 'REMOTE_ADDR'];
    foreach ($ipKeys as $key) {
        if (!empty($parameters[$key])) {
            return $parameters[$key] . ':' . $request->getUri()->getPath();
        }
    }

    // rate limiting will be skipped when an empty bucket name returned
    return '';
};

$rateLimiter = new \RazonYang\Psr\RateLimiter\Middleware($manager, $responseFactory, $nameCallback);
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

2458d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/17720932?v=4)[Razon Yang](/maintainers/RazonYang)[@razonyang](https://github.com/razonyang)

---

Top Contributors

[![razonyang](https://avatars.githubusercontent.com/u/17720932?v=4)](https://github.com/razonyang "razonyang (1 commits)")

---

Tags

middlewarepsr-15rate-limiter

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/razonyang-psr-rate-limiter/health.svg)

```
[![Health](https://phpackages.com/badges/razonyang-psr-rate-limiter/health.svg)](https://phpackages.com/packages/razonyang-psr-rate-limiter)
```

###  Alternatives

[mezzio/mezzio

PSR-15 Middleware Microframework

3883.6M97](/packages/mezzio-mezzio)[laminas/laminas-stratigility

PSR-7 middleware foundation for building and dispatching middleware pipelines

586.6M81](/packages/laminas-laminas-stratigility)[middlewares/utils

Common utils for PSR-15 middleware packages

503.4M92](/packages/middlewares-utils)[yiisoft/rate-limiter

Yii Rate Limiter Middleware

2965.5k](/packages/yiisoft-rate-limiter)[chubbyphp/chubbyphp-framework

A minimal, highly performant middleware PSR-15 microframework built with as little complexity as possible, aimed primarily at those developers who want to understand all the vendors they use.

13544.4k4](/packages/chubbyphp-chubbyphp-framework)[mezzio/mezzio-authentication-oauth2

OAuth2 (server) authentication middleware for Mezzio and PSR-7 applications.

28483.0k2](/packages/mezzio-mezzio-authentication-oauth2)

PHPackages © 2026

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