2017 © Pedro Peláez
 

library laravel-throttle-simultaneous-requests

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

image

imliam/laravel-throttle-simultaneous-requests

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

  • Saturday, July 14, 2018
  • by ImLiam
  • Repository
  • 1 Watchers
  • 15 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Laravel Throttle Simultaneous Requests Middleware

Latest Version on Packagist Total Downloads License, (*1)

Throttle the current user's requests based on how many requests are currently being executed, in case any are time consuming before giving a response., (*2)

This helps when some endpoints are more resource-intensive than others, and stops users from retrying requests that may not have even completed yet., (*3)

This forces users of your API to interact in a different way by queuing their requests appropriately instead of spamming until they reach the request limit., (*4)

When performing an action only the current user can perform, this also helps to ensure that the endpoint has a form of idempotency and any side effects can only occur once until a subsequent request is made., (*5)

Installation

You can install the package with Composer using the following command:, (*6)

composer require imliam/laravel-throttle-simultaneous-requests:^2.0.0

Once installed to your project, add the middleware to your App\Http\Kernel::$routeMiddleware array., (*7)

protected $routeMiddleware = [
    // ...
    'simultaneous' => \ImLiam\ThrottleSimultaneousRequests\ThrottleSimultaneousRequests::class,
];

Usage

You can use the middleware like any other. For example, to limit a particular endpoint to only 3 concurrent requests by the same user:, (*8)

``` php Route::get('/', 'HomeController@index')->middleware('simultaneous:3');, (*9)


### Why not use queues? Queues have their place to defer time consuming tasks to a later date, however they are not always the most appropriate solution for a task. A given task could require use of limited hardware resources, or require some other kind of processing that does not make sense to run concurrently. [See how Stripe use concurrent request limiters...](https://stripe.com/blog/rate-limiters) ### Why is no `Retry-After` header sent? Most typical rate limiting solutions limit a user to a number of requests within a set time period, such as 100 requests per minute, so include a `Retry-After` header to let the requestor know when they are available to try again. This middleware does not add such a header to the response, due to the nature of the request taking a longer amount of time to complete there is no guaranteed time where the requestor can retry the request. Instead, it is up to the requestor to determine when to retry. ## Testing ``` bash composer test

Changelog

Please see CHANGELOG for more information on what has changed recently., (*10)

Contributing

Please see CONTRIBUTING for details., (*11)

Security

If you discover any security related issues, please email liam@liamhammett.com instead of using the issue tracker., (*12)

Credits

License

The MIT License (MIT). Please see License File for more information., (*13)

The Versions

14/07 2018

dev-master

9999999-dev https://github.com/imliam/laravel-throttle-simultaneous-requests

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

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

laravel api middleware throttle imliam laravel-throttle-simultaneous-requests

11/07 2018

v1.0.0

1.0.0.0 https://github.com/imliam/laravel-throttle-simultaneous-requests

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

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

laravel api middleware throttle imliam laravel-throttle-simultaneous-requests