Max wait & fail fast
When you’d rather error than block for too long, cap the wait. A wait above the ceiling — counting every round of it, if the limiter has to wait again after losing a slot to another worker — throws RateLimitExceededException (extends RateLimitException) instead of sleeping:
Http::rateLimit(RateLimits::perHour(10)->maxWait(5_000)) // milliseconds
->get('https://api.example.com/report');Handling the exception
The exception carries the owner key, the wait that would have been needed and your ceiling, so you can reschedule, degrade or report precisely:
use RoundlyConsulting\HttpClientRateLimits\Exceptions\RateLimitExceededException;
use RoundlyConsulting\HttpClientRateLimits\Facades\RateLimits;
try {
$response = Http::rateLimit(RateLimits::perHour(10)->maxWait(5_000))
->get('https://api.example.com/report');
} catch (RateLimitExceededException $e) {
$e->key; // the owner key of the window that forced the wait
$e->delayMs; // the wait that would have been needed
$e->maxWaitMs; // your ceiling (5000)
}The check runs before the RequestDeferred event and before any waiting, so nothing is recorded for the rejected call. In a named profile, set it with the max_wait key (milliseconds).
Show your open-source love
This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.
More ways to support, including cryptoBy donating, you agree to our donation terms.
Want this built into your product?
We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.