PHPackages                             graham-campbell/throttle - 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. [Framework](/categories/framework)
4. /
5. graham-campbell/throttle

ActiveLibrary[Framework](/categories/framework)

graham-campbell/throttle
========================

Throttle Is A Rate Limiter For Laravel

v11.0.0(1y ago)7102.3M—0.4%6211MITPHPPHP ^8.1CI passing

Since Feb 8Pushed 1y ago18 watchersCompare

[ Source](https://github.com/GrahamCampbell/Laravel-Throttle)[ Packagist](https://packagist.org/packages/graham-campbell/throttle)[ GitHub Sponsors](https://github.com/GrahamCampbell)[ Fund](https://tidelift.com/funding/github/packagist/graham-campbell/throttle)[ RSS](/packages/graham-campbell-throttle/feed)WikiDiscussions 11.0 Synced 1mo ago

READMEChangelog (10)Dependencies (8)Versions (52)Used By (11)

Laravel Throttle
================

[](#laravel-throttle)

Laravel Throttle was created by, and is maintained by [Graham Campbell](https://github.com/GrahamCampbell), and is a rate limiter for [Laravel](https://laravel.com/). Feel free to check out the [change log](CHANGELOG.md), [releases](https://github.com/GrahamCampbell/Laravel-Throttle/releases), [security policy](https://github.com/GrahamCampbell/Laravel-Throttle/security/policy), [license](LICENSE), [code of conduct](.github/CODE_OF_CONDUCT.md), and [contribution guidelines](.github/CONTRIBUTING.md).

[![Banner](https://user-images.githubusercontent.com/2829600/71477509-693e3c80-27e2-11ea-8497-46b3a1c8f1f4.png)](https://user-images.githubusercontent.com/2829600/71477509-693e3c80-27e2-11ea-8497-46b3a1c8f1f4.png)

[![Build Status](https://camo.githubusercontent.com/f51c7cffb336ae09a5cb4ee18a37f52aa4687906c7ec7a5390496348c46946e0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f47726168616d43616d7062656c6c2f4c61726176656c2d5468726f74746c652f74657374732e796d6c3f6c6162656c3d5465737473267374796c653d666c61742d737175617265)](https://github.com/GrahamCampbell/Laravel-Throttle/actions?query=workflow%3ATests)[![StyleCI Status](https://camo.githubusercontent.com/3afe2d1b58479285a9e428b466324503406e9754d6a0462b40f9b063a7b4bf01/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f31353433373432372f736869656c64)](https://github.styleci.io/repos/15437427)[![Software License](https://camo.githubusercontent.com/c090e080484e2a2bc766446291d04437db823929042bf614b26a1643660ddf6f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e3f7374796c653d666c61742d737175617265)](LICENSE)[![Packagist Downloads](https://camo.githubusercontent.com/ac4a7c509861096260cbe5093977179446ef586cb85cc10051001df6b961886f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f67726168616d2d63616d7062656c6c2f7468726f74746c653f7374796c653d666c61742d737175617265)](https://packagist.org/packages/graham-campbell/throttle)[![Latest Version](https://camo.githubusercontent.com/6e01097d1ec3341cc871e3c484f15ab9d616f535658353473c8c7a4d43d49e23/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f47726168616d43616d7062656c6c2f4c61726176656c2d5468726f74746c653f7374796c653d666c61742d737175617265)](https://github.com/GrahamCampbell/Laravel-Throttle/releases)

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

[](#installation)

This version requires [PHP](https://www.php.net/) 8.1-8.4 and supports [Laravel](https://laravel.com/) 10-12.

ThrottleL5.5L5.6L5.7L5.8L6L7L8L9L10L11L127.5✅✅✅✅✅✅❌❌❌❌❌8.2❌❌❌❌✅✅✅✅❌❌❌9.0❌❌❌❌❌❌✅✅❌❌❌10.3❌❌❌❌❌❌✅✅✅✅❌11.0❌❌❌❌❌❌❌❌✅✅✅To get the latest version, simply require the project using [Composer](https://getcomposer.org/):

```
$ composer require "graham-campbell/throttle:^11.0"
```

Once installed, if you are not using automatic package discovery, then you need to register the `GrahamCampbell\Throttle\ThrottleServiceProvider` service provider in your `config/app.php`.

You can also optionally alias our facade:

```
        'Throttle' => GrahamCampbell\Throttle\Facades\Throttle::class,
```

Configuration
-------------

[](#configuration)

Laravel Throttle supports optional configuration.

To get started, you'll need to publish all vendor assets:

```
$ php artisan vendor:publish
```

This will create a `config/throttle.php` file in your app that you can modify to set your configuration. Also, make sure you check for changes to the original config file in this package between releases.

There is one config option:

##### Cache Driver

[](#cache-driver)

This option (`'driver'`) defines the cache driver to be used. It may be the name of any driver set in config/cache.php. Setting it to null will use the driver you have set as default in config/cache.php. The default value for this setting is `null`.

Usage
-----

[](#usage)

##### Throttle

[](#throttle)

This is the class of most interest. It is bound to the ioc container as `'throttle'` and can be accessed using the `Facades\Throttle` facade. There are six public methods of interest.

The `'get'` method will create a new throttler class (a class that implements `Throttler\ThrottlerInterface`) from the 1-3 parameters that you pass to it. The first parameter is required and must either an instance of `\Illuminate\Http\Request`, or an associative array with two keys (`'ip'` should be the ip address of the user you wish to throttle and `'route'` should be the full url you wish to throttle, but actually, for advanced usage, may be any unique key you choose). The second parameter is optional and should be an `int` which represents the maximum number of hits that are allowed before the user hits the limit. The third and final parameter should be an `int` that represents the time the user must wait after going over the limit before the hit count will be reset to zero. Under the hood this method will be calling the make method on a throttler factory class (a class that implements `Factories\FactoryInterface`).

The other 5 methods all accept the same parameters as the `get` method. What happens here is we dynamically create a throttler class (or we automatically reuse an instance we already created), and then we call the method on it with no parameters. These 5 methods are `'attempt'`, `'hit'`, `'clear'`, `'count'`, and `'check'`. They are all documented bellow.

##### Facades\\Throttle

[](#facadesthrottle)

This facade will dynamically pass static method calls to the `'throttle'` object in the ioc container which by default is the `Throttle` class.

##### Throttler\\ThrottlerInterface

[](#throttlerthrottlerinterface)

This interface defines the public methods a throttler class must implement. All 5 methods here accept no parameters.

The `'attempt'` method will hit the throttle (increment the hit count), and then will return a boolean representing whether or not the hit limit has been exceeded.

The `'hit'` method will hit the throttle (increment the hit count), and then will return `$this` so you can make another method call if you so choose.

The `'clear'` method will clear the throttle (set the hit count to zero), and then will return `$this` so you can make another method call if you so choose.

The `'count'` method will return the number of hits to the throttle.

The `'check'` method will return a boolean representing whether or not the hit limit has been exceeded.

##### Throttler\\CacheThrottler

[](#throttlercachethrottler)

This class implements `Throttler\ThrottlerInterface` completely. This is the only throttler implementation shipped with this package, and in created by the `Factories\CacheFactory` class. Note that this class also implements PHP's `Countable` interface.

##### Factories\\FactoryInterface

[](#factoriesfactoryinterface)

This interface defines the public methods a throttler factory class must implement. Such a class must only implement one method.

The `'make'` method will create a new throttler class (a class that implements `Throttler\ThrottlerInterface`) from data object you pass to it. This documentation of an internal interface is included for advanced users who may wish to write their own factory classes to make their own custom throttler classes.

##### Factories\\CacheFactory

[](#factoriescachefactory)

This class implements `Factories\FactoryInterface` completely. This is the only throttler implementation shipped with this package, and is responsible for creating the `Factories\CacheFactory` class. This class is only intended for internal use by the `Throttle` class.

##### Http\\Middleware\\ThrottleMiddleware

[](#httpmiddlewarethrottlemiddleware)

You may put the `GrahamCampbell\Throttle\Http\Middleware\ThrottleMiddleware` middleware in front of your routes to throttle them. The middleware can take up to two parameters. The two parameters are `limit` and `time`. It may be useful for you to take a look at the [source](https://github.com/GrahamCampbell/Laravel-Throttle/blob/11.0/src/Http/Middleware/ThrottleMiddleware.php) for this, read the [tests](https://github.com/GrahamCampbell/Laravel-Throttle/blob/11.0/tests/Functional/MiddlewareTest.php), or check out Laravel's [documentation](https://laravel.com/docs/11.x/middleware) if you need to.

##### ThrottleServiceProvider

[](#throttleserviceprovider)

This class contains no public methods of interest. This class should be added to the providers array in `config/app.php`. This class will setup ioc bindings.

##### Real Examples

[](#real-examples)

Here you can see an example of just how simple this package is to use.

Our first example will be a super simple usage of our default middleware. This will setup a middleware for that url with a limit of 10 hits and a retention time of 1 hour.

```
use Illuminate\Support\Facades\Route;

Route::get('foo', ['middleware' => 'GrahamCampbell\Throttle\Http\Middleware\ThrottleMiddleware', function () {
    return 'Why herro there!';
}]);
```

What if we want custom limits? Easy! Laravel allows us to pass parameters to a middleware. This will setup a middleware for that url with a limit of 50 hits and a retention time of 30 mins.

```
use Illuminate\Support\Facades\Route;

Route::get('foo', ['middleware' => 'GrahamCampbell\Throttle\Http\Middleware\ThrottleMiddleware:50,30', function () {
    return 'Why herro there!';
}]);
```

What if we don't want to use the default middleware provided with this package? Well, that's easy too.

```
use GrahamCampbell\Throttle\Facades\Throttle;
use Illuminate\Support\Facades\Request;

// now let's get a throttler object for that request
// we'll use the same config as in the previous example
// note that only the first parameter is "required"
$throttler = Throttle::get(Request::instance(), 50, 30);

// let's check if we've gone over the limit
var_dump($throttler->check());

// we implement Countable
var_dump(count($throttler));

// there are a few more functions available
// please see the previous documentation
```

Also note that you can call methods straight on the factory instead of calling the get method.

```
use GrahamCampbell\Throttle\Facades\Throttle;
use Illuminate\Support\Facades\Request;

$request = Request::instance();

// the attempt function will hit the throttle, then return check
var_dump(Throttle::attempt($request));

// so this is the same as writing
var_dump(Throttle::hit($request)->check());

// and, of course, the same as
var_dump(Throttle::get($request)->attempt());
```

##### Further Information

[](#further-information)

There are other classes in this package that are not documented here (such as the transformers). This is because they are not intended for public use and are used internally by this package.

Security
--------

[](#security)

If you discover a security vulnerability within this package, please send an email to . All security vulnerabilities will be promptly addressed. You may view our full security policy [here](https://github.com/GrahamCampbell/Laravel-Throttle/security/policy).

License
-------

[](#license)

Laravel Throttle is licensed under [The MIT License (MIT)](LICENSE).

For Enterprise
--------------

[](#for-enterprise)

Available as part of the Tidelift Subscription

The maintainers of `graham-campbell/throttle` and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/packagist-graham-campbell-throttle?utm_source=packagist-graham-campbell-throttle&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)

###  Health Score

61

—

FairBetter than 99% of packages

Maintenance44

Moderate activity, may be stable

Popularity63

Solid adoption and visibility

Community34

Small or concentrated contributor base

Maturity85

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 97.5% 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 ~79 days

Recently: every ~87 days

Total

52

Last Release

442d ago

Major Versions

v7.5.1 → v8.0.12020-04-14

7.5.x-dev → v8.1.02020-08-14

8.2.x-dev → 9.0.x-dev2022-05-30

v9.0.0 → v10.0.02023-03-07

10.3.x-dev → 11.0.x-dev2025-03-03

PHP version history (8 changes)v0.1.0-alphaPHP &gt;=5.4.7

v4.0.0PHP &gt;=5.5.9

v6.0.0PHP ^7.0

v7.0.0PHP ^7.1.3

v8.0.0PHP ^7.2.5

v8.1.0PHP ^7.2.5 || ^8.0

9.0.x-devPHP ^7.4.15 || ^8.0.2

11.0.x-devPHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/d95eb26cb8f3919bb5ca3b6d823daeabbf259663778a970349b245c580713c8e?d=identicon)[graham-campbell](/maintainers/graham-campbell)

---

Top Contributors

[![GrahamCampbell](https://avatars.githubusercontent.com/u/2829600?v=4)](https://github.com/GrahamCampbell "GrahamCampbell (390 commits)")[![lazychaser](https://avatars.githubusercontent.com/u/2094856?v=4)](https://github.com/lazychaser "lazychaser (2 commits)")[![jitendra-1217](https://avatars.githubusercontent.com/u/5562241?v=4)](https://github.com/jitendra-1217 "jitendra-1217 (2 commits)")[![RatkoR](https://avatars.githubusercontent.com/u/6648783?v=4)](https://github.com/RatkoR "RatkoR (2 commits)")[![sunspikes](https://avatars.githubusercontent.com/u/75611?v=4)](https://github.com/sunspikes "sunspikes (1 commits)")[![josephmarksjr](https://avatars.githubusercontent.com/u/6662278?v=4)](https://github.com/josephmarksjr "josephmarksjr (1 commits)")[![m1guelpf](https://avatars.githubusercontent.com/u/23558090?v=4)](https://github.com/m1guelpf "m1guelpf (1 commits)")[![Djuki](https://avatars.githubusercontent.com/u/416411?v=4)](https://github.com/Djuki "Djuki (1 commits)")

---

Tags

hacktoberfestframeworklaravelGraham CampbellGrahamCampbellrate limitthrottlethrottlingLaravel Throttle

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/graham-campbell-throttle/health.svg)

```
[![Health](https://phpackages.com/badges/graham-campbell-throttle/health.svg)](https://phpackages.com/packages/graham-campbell-throttle)
```

###  Alternatives

[graham-campbell/markdown

Markdown Is A CommonMark Wrapper For Laravel

1.3k7.1M64](/packages/graham-campbell-markdown)[graham-campbell/manager

Manager Provides Some Manager Functionality For Laravel

39221.1M134](/packages/graham-campbell-manager)[laravel/pulse

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

1.7k12.1M99](/packages/laravel-pulse)[graham-campbell/github

GitHub Is A GitHub Bridge For Laravel

6411.7M19](/packages/graham-campbell-github)[graham-campbell/exceptions

Provides A Powerful Error Response System For Both Development And Production

5911.3M4](/packages/graham-campbell-exceptions)[laravel-zero/framework

The Laravel Zero Framework.

3371.4M369](/packages/laravel-zero-framework)

PHPackages © 2026

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