Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

adg76's avatar
Level 1

Throttle middleware counting each hit as two hits

I have been unable to track this down for a full day now and am out of ideas of where to look.

It seems that the Laravel 5.4 built-in throttle middleware is seeing all my individual GET requests as two requests.

Here's my API route:

Route::group(['middleware' => 'auth:api'], function () {
    Route::get('inventory', ['uses' => 'InventoryController@index', 'middleware' => 'throttle:5,2'], function () {});
});

Using Postman, I issue a single GET request to the inventory route. In the cache, I see the timestamp and hit count like this:

1489436639i:2;

On a second GET request, the cache records this:

1489436639i:4;

Again, it doubles the count.

For every single GET request, it's registering as two hits. My inventory code is very simple, and there are no redirects for other calls to the server made. I've confirmed this by looking at the Apache request logs, and only one Apache access log entry is recorded for each GET request.

I'm on the latest code as of this morning (just did a composer update). I also confirmed this behaviour is happening on another server to which the code is deployed.

Any help would be greatly appreciated!

0 likes
2 replies
gustavoweb's avatar

Oops, this happens because of the following: You are defining the middleware within the api route, but by default Laravel already implements middleware for any request made to api.

Take a look at Kernel.php:

'api' => [
    'throttle:60,1',
    'bindings',
],

So you have a middleware request from Kernel and another one from your route file. Your result will always double in this case!

3 likes
MladenJanjetovic's avatar

@gustavoweb This may also occur if there are multiple throttles defined in a single route definition:

Route::middleware(['throttle:5,1', 'throttle:10,60'])->group(...);

Please or to participate in this conversation.