PHPackages                             philiprehberger/laravel-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. philiprehberger/laravel-rate-limiter

ActiveLibrary

philiprehberger/laravel-rate-limiter
====================================

Advanced rate limiting with sliding window, token bucket, and per-entity controls for Laravel.

v1.1.1(4d ago)15MITPHPPHP ^8.2CI passing

Since Mar 9Pushed 3d agoCompare

[ Source](https://github.com/philiprehberger/laravel-rate-limiter)[ Packagist](https://packagist.org/packages/philiprehberger/laravel-rate-limiter)[ Docs](https://github.com/philiprehberger/laravel-rate-limiter)[ RSS](/packages/philiprehberger-laravel-rate-limiter/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (10)Versions (4)Used By (0)

Laravel Rate Limiter
====================

[](#laravel-rate-limiter)

[![Tests](https://github.com/philiprehberger/laravel-rate-limiter/actions/workflows/tests.yml/badge.svg)](https://github.com/philiprehberger/laravel-rate-limiter/actions/workflows/tests.yml)[![Latest Version on Packagist](https://camo.githubusercontent.com/0f37b1c7c89cacc1f50a9ae733782068d7c6bfafbcb5c20121c3306079500f4a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068696c69707265686265726765722f6c61726176656c2d726174652d6c696d697465722e737667)](https://packagist.org/packages/philiprehberger/laravel-rate-limiter)[![License](https://camo.githubusercontent.com/995967e4bdff72533b25608c36c1ba937d577bf39909b8b952c0be6cdb75ce91/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7068696c69707265686265726765722f6c61726176656c2d726174652d6c696d69746572)](LICENSE)

Advanced rate limiting with sliding window, token bucket, and per-entity controls for Laravel.

Requirements
------------

[](#requirements)

- PHP 8.2+
- Laravel 11 or 12

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

[](#installation)

```
composer require philiprehberger/laravel-rate-limiter
```

The service provider is auto-discovered. Optionally publish the config:

```
php artisan vendor:publish --tag=rate-limiter-config
```

Usage
-----

[](#usage)

### Quick Start

[](#quick-start)

```
use PhilipRehberger\RateLimiter\Facades\RateLimit;

// Rate limit by arbitrary key
$result = RateLimit::for('global-api')
    ->allow(1000)
    ->perHour()
    ->attempt();

if ($result->denied()) {
    return response()->json(['message' => 'Slow down'], 429, $result->headers());
}
```

### Entry Points

[](#entry-points)

```
// Arbitrary key
RateLimit::for('some-key');

// Scoped to an authenticated user
RateLimit::forUser($request->user());

// Scoped to an IP address
RateLimit::forIp($request->ip());
```

### Configuring the Limit

[](#configuring-the-limit)

```
RateLimit::for('key')
    ->allow(100)         // max attempts per window (must be >= 1)
    ->perMinute()        // window = 60 seconds (per() requires >= 1)
    ->algorithm('sliding')
    ->cost(1)            // tokens to consume per attempt
    ->on('export');      // composite key: "key:export"
```

### Algorithms

[](#algorithms)

AlgorithmStringBest ForFixed Window`'fixed'`Internal tooling, scenarios where boundary bursts are acceptableSliding Window`'sliding'` (default)Public APIs, auth endpoints, strict burst preventionToken Bucket`'token_bucket'`Upload/download throttling, expensive compute endpoints### Middleware

[](#middleware)

Apply to routes via the `rate-limit` alias:

```
// 100 requests per 60 seconds, sliding window
Route::middleware('rate-limit:100,60,sliding')->group(function () {
    Route::get('/api/posts', [PostController::class, 'index']);
});
```

### Configuration

[](#configuration)

`config/rate-limiter.php`:

```
return [
    'default_algorithm' => env('RATE_LIMITER_ALGORITHM', 'sliding'),
    'cache_store'       => env('RATE_LIMITER_CACHE_STORE', null),
    'prefix'            => env('RATE_LIMITER_PREFIX', 'rate_limit'),
];
```

API
---

[](#api)

### RateLimit Facade / Entry Points

[](#ratelimit-facade--entry-points)

MethodDescription`RateLimit::for(string $key)`Create a pending limit for an arbitrary key`RateLimit::forUser(Authenticatable $user)`Create a pending limit scoped to a user`RateLimit::forIp(string $ip)`Create a pending limit scoped to an IP address### PendingRateLimit (Fluent Builder)

[](#pendingratelimit-fluent-builder)

MethodDescription`->allow(int $limit)`Set the maximum attempts per window`->perSecond()`Set window to 1 second`->perMinute()`Set window to 60 seconds`->perHour()`Set window to 3,600 seconds`->perDay()`Set window to 86,400 seconds`->per(int $seconds)`Set a custom window in seconds`->algorithm(string $algo)`Set algorithm: `'fixed'`, `'sliding'`, or `'token_bucket'``->cost(int $cost)`Set token cost per attempt (default: 1)`->on(string $action)`Append an action suffix to the key`->attempt()`Consume tokens and return a `RateLimitResult``->check()`Inspect state without consuming tokens### RateLimitResult

[](#ratelimitresult)

Property / MethodTypeDescription`->allowed()``bool`Whether the attempt was allowed`->denied()``bool`Whether the attempt was denied`->remaining``int`Remaining tokens in current window`->limit``int`Configured limit`->retryAfter``int|null`Seconds until allowed; `null` if allowed`->resetAt``int`Unix timestamp of next window reset`->headers()``array`Standard HTTP rate limit headers### Middleware Parameters

[](#middleware-parameters)

PositionParameterDefault1`maxAttempts`602`windowSeconds`603`algorithm`config defaultDevelopment
-----------

[](#development)

```
composer install
vendor/bin/phpunit
vendor/bin/pint --test
vendor/bin/phpstan analyse
```

License
-------

[](#license)

MIT

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance99

Actively maintained with recent releases

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity48

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

Every ~4 days

Total

3

Last Release

4d ago

### Community

Maintainers

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

---

Top Contributors

[![philiprehberger](https://avatars.githubusercontent.com/u/8218077?v=4)](https://github.com/philiprehberger "philiprehberger (10 commits)")

---

Tags

middlewarelaravelthrottlerate limitingtoken bucketsliding-window

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/philiprehberger-laravel-rate-limiter/health.svg)

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

###  Alternatives

[imliam/laravel-throttle-simultaneous-requests

Throttle the current user's requests based on how many requests are currently being executed.

4623.0k](/packages/imliam-laravel-throttle-simultaneous-requests)[spinen/laravel-browser-filter

Filters http requests based on browser type.

2046.0k](/packages/spinen-laravel-browser-filter)[shahghasiadil/laravel-api-versioning

Elegant attribute-based API versioning solution for Laravel applications with built-in deprecation management and version inheritance

2912.6k](/packages/shahghasiadil-laravel-api-versioning)

PHPackages © 2026

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