yiisoft/yii2 · error · TooManyRequestsHttpException
Rate limit exceeded.
Error message
Rate limit exceeded.
What it means
Error "Rate limit exceeded." thrown in yiisoft/yii2.
Source
Thrown at framework/filters/RateLimiter.php:142
* @param Action $action the action to be executed
* @throws TooManyRequestsHttpException if rate limit exceeds
*/
public function checkRateLimit($user, $request, $response, $action)
{
list($limit, $window) = $user->getRateLimit($request, $action);
list($allowance, $timestamp) = $user->loadAllowance($request, $action);
$current = time();
$allowance += (int) (($current - $timestamp) * $limit / $window);
if ($allowance > $limit) {
$allowance = $limit;
}
if ($allowance < 1) {
$user->saveAllowance($request, $action, 0, $current);
$this->addRateLimitHeaders($response, $limit, 0, $window);
throw new TooManyRequestsHttpException($this->errorMessage);
}
$user->saveAllowance($request, $action, $allowance - 1, $current);
$this->addRateLimitHeaders($response, $limit, $allowance - 1, (int) (($limit - $allowance + 1) * $window / $limit));
}
/**
* Adds the rate limit headers to the response.
* @param Response $response
* @param int $limit the maximum number of allowed requests during a period
* @param int $remaining the remaining number of allowed requests within the current period
* @param int $reset the number of seconds to wait before having maximum number of allowed requests again
*/
public function addRateLimitHeaders($response, $limit, $remaining, $reset)
{
if ($this->enableRateLimitHeaders) {
$response->getHeaders()
->set('X-Rate-Limit-Limit', $limit)View on GitHub (pinned to 66f00d18a2)
When it happens
Trigger: Thrown at framework/filters/RateLimiter.php:142 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of yiisoft/yii2@66f00d18a2 (2026-08-17).
Data as JSON: /api/errors/6355116160ce93ff.
Report an issue: GitHub.