# RateLimitInterface

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

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [filters](/docs/api/yii/filters/index.md) › RateLimitInterface

| interface | `yii\filters\RateLimitInterface` |
| --- | --- |
| Since | 2.0 |
| Source | [`framework/filters/RateLimitInterface.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/filters/RateLimitInterface.php#L19) |

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

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`getRateLimit()`](#method-getRateLimit) abstract | Returns the maximum number of allowed requests and the window size. | `RateLimitInterface` |
| [`loadAllowance()`](#method-loadAllowance) abstract | Loads the number of allowed requests and the corresponding timestamp from a persistent storage. | `RateLimitInterface` |
| [`saveAllowance()`](#method-saveAllowance) abstract | Saves the number of allowed requests and the corresponding timestamp to a persistent storage. | `RateLimitInterface` |

## Method details

### getRateLimit() <span id="method-getRateLimit"></span>

```php
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**

| Parameter | Type | Description |
| --- | --- | --- |
| `$request` | [`yii\web\Request`](/docs/api/yii/web/request/index.md) | The current request |
| `$action` | [`yii\base\Action`](/docs/api/yii/base/action/index.md) | The 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.

### loadAllowance() <span id="method-loadAllowance"></span>

```php
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**

| Parameter | Type | Description |
| --- | --- | --- |
| `$request` | [`yii\web\Request`](/docs/api/yii/web/request/index.md) | The current request |
| `$action` | [`yii\base\Action`](/docs/api/yii/base/action/index.md) | The 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.

### saveAllowance() <span id="method-saveAllowance"></span>

```php
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**

| Parameter | Type | Description |
| --- | --- | --- |
| `$request` | [`yii\web\Request`](/docs/api/yii/web/request/index.md) | The current request |
| `$action` | [`yii\base\Action`](/docs/api/yii/base/action/index.md) | The action to be executed |
| `$allowance` | `int` | The number of allowed requests remaining. |
| `$timestamp` | `int` | The current timestamp. |

**Returns**

`mixed`