Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable rate limiter in Laravel?

Tags:

php

laravel

Is there a way to disable rate limiting on every/individual routes in Laravel?

I'm trying to test an endpoint that receives a lot of requests, but randomly Laravel will start responding with { status: 429, responseText: 'Too Many Attempts.' } for a few hundred requests which makes testing a huge pain.

like image 929
SimpleJ Avatar asked Mar 27 '17 23:03

SimpleJ


People also ask

How do I disable rate limiting in Laravel?

A: For disabling the rate limiter in Laravel, first go to the app/Http/Kernel. php. There you will find the default throttle limit defined by Laravel for all api routes. Just comment out that code to disable it completely.

What is Laravel API rate limit?

Laravel API rate limiting 100 requests per minute.

How does Laravel rate limit work?

There are two ways to implement rate limiting with Laravel: Using the Rate Limiter Middleware: to rate limiting incoming HTTP requests before reaching the controller. Using the Rate Limiting abstraction: to interact more finely with the rate limiter at the controller level.

What is Ratelimiter in Laravel?

Laravel includes a simple to use rate limiting abstraction which, in conjunction with your application's cache, provides an easy way to limit any action during a specified window of time. If you are interested in rate limiting incoming HTTP requests, please consult the rate limiter middleware documentation.


3 Answers

In app/Http/Kernel.php Laravel has a default throttle limit for all api routes.

protected $middlewareGroups = [     ...     'api' => [         'throttle:60,1',     ], ]; 

Comment or increase it.

like image 71
EddyTheDove Avatar answered Oct 06 '22 18:10

EddyTheDove


You can actually disable only a certain middleware in tests.

use Illuminate\Routing\Middleware\ThrottleRequests;

class YourTest extends TestCase 
{

    protected function setUp()
    {
        parent::setUp();
        $this->withoutMiddleware(
            ThrottleRequests::class
        );
    }
    ...
}
like image 28
Mostafa Bahri Avatar answered Oct 06 '22 19:10

Mostafa Bahri


Assuming you are using the API routes then you can change the throttle in app/Http/Kernel.php or take it off entirely. If you need to throttle for the other routes you can register the middleware for them separately.

(example below: throttle - 60 attempts then locked out for 1 minute)

'api' => [
        'throttle:60,1',
        'bindings',
    ],
like image 31
cyclops1101 Avatar answered Oct 06 '22 17:10

cyclops1101