Releases: kasapdev/php-rate-limiter
Releases · kasapdev/php-rate-limiter
Release list
v1.2.0
Adds LeakyBucketLimiter, a new leaky bucket rate limiting algorithm alongside the existing token bucket and sliding window limiters.
Each key gets a fixed-capacity queue that leaks (drains) at a constant configured rate (requests/second). Every attempt() first leaks the bucket based on elapsed wall-clock time since the last recorded state, then either queues the request (returns true) or rejects it outright (returns false) if the bucket is already at capacity.
- Reuses the existing pluggable StorageInterface (works with both ArrayStorage and FileStorage) — no new storage mechanism.
- Follows the same constructor/method conventions as TokenBucketLimiter and SlidingWindowLimiter: __construct(StorageInterface $storage, int $capacity, float $leakRatePerSecond), attempt(string $key): bool, remaining(string $key): int.
- New deterministic tests cover capacity exhaustion, leak-over-time behavior (simulated via direct storage timestamp manipulation, no sleep()), the zero-capacity edge case, and FileStorage interoperability.
- README: new '## Leaky Bucket Limiter' usage section with a runnable example, an updated API reference, and a new realistic end-to-end HTTP rate-limiting middleware example under '## Usage'.