macroman/rate-limiter

General framework agnostic rate limiter

Installs: 3 407

Dependents: 0

Suggesters: 0

Security: 0

Stars: 9

Watchers: 1

Forks: 2

Open Issues: 0

pkg:composer/macroman/rate-limiter

1.0.3 2022-02-28 09:59 UTC

This package is auto-updated.

Last update: 2025-10-28 17:37:58 UTC


README

General framework agnostic rate limiter

Useful when consuming a rate limited API

Installation

composer require macroman/rate-limiter

Usage

Initialize Limiter with a frequecy and duration

// example.php
use RateLimiter\Limiter;

// Limit to 6 iterations per second
$limiter = new Limiter(6, 1);

for ($i = 0; $i < 50; $i++) {
    $limiter->await();

    // Make your rate limited call here
    echo "Iteration $i" . PHP_EOL;
}

License

See LICENSE