bentools/funnel-http-client

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

1.1 2024-10-18 08:14 UTC

This package is auto-updated.

Last update: 2024-11-18 08:28:15 UTC


README

Latest Stable Version License CI Workflow 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.