A Laravel (5.6 upwards) wrapper for Guzzle Advanced Throttle.
Via Composer
$ composer require hamburgscleanest/laravel-guzzle-throttle
Everything is automatically registered for you.
Publish the config to get the example configuration.
$ php artisan vendor:publish
20 requests every 1 seconds
100 requests every 2 minutes
return [
'cache' => [
// Name of the configured driver in the Laravel cache config file / Also needs to be set when "no-cache" is set! Because it's used for the internal timers
'driver' => 'default',
// Cache strategy: no-cache, cache, force-cache
'strategy' => 'cache',
// TTL in minutes
'ttl' => 900
],
'rules' => [
[
// host (including scheme)
'host' => 'https://www.google.com',
// maximum number of requests in the given interval
'max_requests' => 20,
// interval in seconds till the limit is reset
'request_interval' => 1
],
[
// host (including scheme)
'host' => 'https://www.google.com',
// maximum number of requests in the given interval
'max_requests' => 100,
// interval in seconds till the limit is reset
'request_interval' => 120
]
]
];
If you want to know more about the possible configurations, head over to the middleware repository: Guzzle Advanced Throttle.
Using the preconfigured client is super easy. You just have to instantiate your client like this:
// returns an instance of GuzzleHttp\Client
$client = GuzzleThrottle::client(['base_uri' => 'https://www.google.com']);
After that you can use all off the usual GuzzleHttp\Client
methods, e.g.
$client->get('/test'));
Please see CHANGELOG for more information on what has changed recently.
$ composer test
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.