Skip to content
PHP Ecosystem
Explore

RateLimitInterface

API reference › yii › filters › RateLimitInterface

interfaceyii\filters\RateLimitInterface
Since2.0
Sourceframework/filters/RateLimitInterface.php

RateLimitInterface is the interface that may be implemented by an identity object to enforce rate limiting.

MethodDescriptionDefined by
getRateLimit() abstractReturns the maximum number of allowed requests and the window size.RateLimitInterface
loadAllowance() abstractLoads the number of allowed requests and the corresponding timestamp from a persistent storage.RateLimitInterface
saveAllowance() abstractSaves the number of allowed requests and the corresponding timestamp to a persistent storage.RateLimitInterface
abstract public function getRateLimit(yii\web\Request $request, yii\base\Action $action): array

Returns the maximum number of allowed requests and the window size.

Parameters

ParameterTypeDescription
$requestyii\web\RequestThe current request
$actionyii\base\ActionThe action to be executed

Returns

array: An array of two elements. The first element is the maximum number of allowed requests, and the second element is the size of the window in seconds.

abstract public function loadAllowance(yii\web\Request $request, yii\base\Action $action): array

Loads the number of allowed requests and the corresponding timestamp from a persistent storage.

Parameters

ParameterTypeDescription
$requestyii\web\RequestThe current request
$actionyii\base\ActionThe action to be executed

Returns

array: An array of two elements. The first element is the number of allowed requests, and the second element is the corresponding UNIX timestamp.

abstract public function saveAllowance(yii\web\Request $request, yii\base\Action $action, int $allowance, int $timestamp): mixed

Saves the number of allowed requests and the corresponding timestamp to a persistent storage.

Parameters

ParameterTypeDescription
$requestyii\web\RequestThe current request
$actionyii\base\ActionThe action to be executed
$allowanceintThe number of allowed requests remaining.
$timestampintThe current timestamp.

Returns

mixed