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 1w 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

21

—

LowBetter than 17% of packages

Maintenance37

Infrequent updates — may be unmaintained

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

564d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/12448739?v=4)[Md. Habibur Rahman](/maintainers/hbrawnak)[@hbrawnak](https://github.com/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

[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)
