bentools/funnel-http-client

A throttler for symfony/http-client to handle rate limits

dev-master / 1.0.x-dev 2019-06-25 14:52 UTC

README

Latest Stable Version License Build Status Coverage Status Quality Score Total Downloads

🚦 Funnel Http Client

A decorator for symfony/http-client to throttle requests subject to rate-limits.

Installation

composer require bentools/funnel-http-client:1.0.x-dev

Usage

use BenTools\FunnelHttpClient\FunnelHttpClient;
use Symfony\Component\HttpClient\HttpClient;

$client = FunnelHttpClient::throttle(HttpClient::create(), $maxRequests = 3, $timeWindow = 5);

$client->request('GET', 'http://foo.bar');
$client->request('GET', 'http://foo.bar');
$client->request('GET', 'http://foo.bar');

$client->request('GET', 'http://foo.bar'); // Will wait a little before being actually triggered

Tests

./vendor/bin/phpunit

License

MIT.