PHPackages                             hbrawnak/limitr - 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. hbrawnak/limitr

ActiveLibrary[Caching](/categories/caching)

hbrawnak/limitr
===============

A middleware-agnostic rate limitr with dynamic rules and storage backends support

1.0.0(1y ago)04MITPHPPHP &gt;=7.0

Since Jan 30Pushed 1y ago1 watchersCompare

[ Source](https://github.com/hbrawnak/limitr)[ Packagist](https://packagist.org/packages/hbrawnak/limitr)[ RSS](/packages/hbrawnak-limitr/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

Limitr Documentation
--------------------

[](#limitr-documentation)

### Installation

[](#installation)

#### Requirements

[](#requirements)

- PHP 7.0 or higher
- Redis

#### Install via Composer

[](#install-via-composer)

```
composer require hbrawnak/limitr

```

### Configuration

[](#configuration)

#### 1. Choose a Storage Driver

[](#1-choose-a-storage-driver)

Redis Storage

```
$redis = new \Redis();
$redis->connect('127.0.0.1');
$storage = new \Hbrawnak\Limitr\Drivers\RedisStorage($redis);

```

#### 2. Create Rate Limit Rules

[](#2-create-rate-limit-rules)

```
use Hbrawnak\Limitr\Rules\RateLimitRule;

$rules = [
    new RateLimitRule('api-ip-limit', 100, 60, 'ip', 3600, 5),
    new RateLimitRule('user-limit', 1000, 3600, 'user_id')
];

```

### Basic Usage

[](#basic-usage)

#### 1. Implement Request Context

[](#1-implement-request-context)

```
class MyRequestContext implements \Hbrawnak\Limitr\Contracts\RequestContext
{
    public function getIp(): string
    {
        return $_SERVER['REMOTE_ADDR'];
    }

    public function getUserId(): ?string
    {
        return Auth::id() ?? null;
    }

    public function getEndpoint(): string
    {
        return $_SERVER['REQUEST_URI'];
    }
}

```

#### 2. Initialize Rate Limiter

[](#2-initialize-rate-limiter)

```
use Hbrawnak\Limitr\RateLimiter;
use Hbrawnak\Limitr\Blocklist;

$blocklist = new Blocklist($storage);
$limiter = new RateLimiter($storage, $blocklist, $rules);

```

#### 3. Apply Rate Limiting

[](#3-apply-rate-limiting)

```
try {
    $context = new MyRequestContext();
    $limiter->check($context);

    // Application logic here

} catch (\Hbrawnak\Limitr\Exceptions\RateLimitExceededException $e) {
    http_response_code(429);
    foreach ($e->getHeaders() as $name => $value) {
        header("$name: $value");
    }
    exit;
}

```

### Advanced Configuration

[](#advanced-configuration)

#### Multiple Rules Combination

[](#multiple-rules-combination)

```
$rules = [
    // Global IP limit
    new RateLimitRule('global-ip', 1000, 3600, 'ip'),

    // Endpoint-specific limit
    new RateLimitRule('login-endpoint', 5, 60, 'endpoint'),

    // User-based limit
    new RateLimitRule('premium-users', 10000, 86400, 'user_id', 86400, 3)
];

```

#### Manual Block Management

[](#manual-block-management)

```
// Block an IP
$blocklist->block('ip:203.0.113.42', 86400);

// Remove block
$blocklist->removeBlock('ip:203.0.113.42');

// Check block status
if ($blocklist->isBlocked('ip:203.0.113.42')) {
    // Handle blocked request
}

```

### Author:

[](#author)

[Md Habibur Rahman](https://habib.im)

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance42

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

 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

473d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7b64703ce57d9c2361c167bf592aeb5f45596b57339d2a93b276e62eb1aa97ef?d=identicon)[hbrawnak](/maintainers/hbrawnak)

---

Top Contributors

[![hbrawnak](https://avatars.githubusercontent.com/u/12448739?v=4)](https://github.com/hbrawnak "hbrawnak (11 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/hbrawnak-limitr/health.svg)

```
[![Health](https://phpackages.com/badges/hbrawnak-limitr/health.svg)](https://phpackages.com/packages/hbrawnak-limitr)
```

###  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)[react/cache

Async, Promise-based cache interface for ReactPHP

444112.4M40](/packages/react-cache)[wp-media/wp-rocket

Performance optimization plugin for WordPress

7431.3M3](/packages/wp-media-wp-rocket)[illuminate/cache

The Illuminate Cache package.

12835.6M1.4k](/packages/illuminate-cache)[colinmollenhour/php-redis-session-abstract

A Redis-based session handler with optimistic locking

6325.6M14](/packages/colinmollenhour-php-redis-session-abstract)

PHPackages © 2026

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