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. [HTTP &amp; Networking](/categories/http)
4. /
5. philiprehberger/laravel-rate-limiter

ActiveLibrary[HTTP &amp; Networking](/categories/http)

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

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

v1.1.1(1mo ago)15[2 PRs](https://github.com/philiprehberger/laravel-rate-limiter/pulls)MITPHPPHP ^8.2CI passing

Since Mar 9Pushed 1mo 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 1mo ago

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

40

—

FairBetter than 88% of packages

Maintenance89

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

56d 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 (16 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

[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k12.1M99](/packages/laravel-pulse)[omniphx/forrest

A Laravel library for Salesforce

2724.4M8](/packages/omniphx-forrest)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)[hamburgscleanest/guzzle-advanced-throttle

A Guzzle middleware that can throttle requests according to (multiple) defined rules. It is also possible to define a caching strategy, e.g. get response from cache when rate limit is exceeded or always get cached value to spare your rate limits.

13033.4k1](/packages/hamburgscleanest-guzzle-advanced-throttle)[hamburgscleanest/laravel-guzzle-throttle

A Laravel wrapper for https://github.com/hamburgscleanest/guzzle-advanced-throttle.

7914.3k](/packages/hamburgscleanest-laravel-guzzle-throttle)

PHPackages © 2026

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