Skip to content

IpRateLimitIdentity ​

Type
Class
Namespace
craft\filters
Inherits
craft\filters\IpRateLimitIdentity » yii\base\BaseObject
Implements
yii\base\Configurable, yii\filters\RateLimitInterface
Since
5.9.15

IP-based rate limit identity for use with RateLimiter.

This class implements RateLimitInterface to provide IP-based rate limiting for unauthenticated requests, using cache storage for allowance tracking.

View source

Public Properties ​

PropertyDescription
ipstring – The IP address to rate limit
keyPrefixstring – Cache key prefix for storing allowance data
limitinteger – Maximum number of requests allowed within the window
windowinteger – Time window in seconds

ip ​

Type
string
Default value
null

The IP address to rate limit

View source

keyPrefix ​

Type
string
Default value
null

Cache key prefix for storing allowance data

View source

limit ​

Type
integer
Default value
null

Maximum number of requests allowed within the window

View source

window ​

Type
integer
Default value
null

Time window in seconds

View source

Public Methods ​

MethodDescription
__call()Calls the named method which is not a class method.
__construct()Constructor.
__get()Returns the value of an object property.
__isset()Checks if a property is set, i.e. defined and not null.
__set()Sets value of an object property.
__unset()Sets an object property to null.
canGetProperty()Returns a value indicating whether a property can be read.
canSetProperty()Returns a value indicating whether a property can be set.
className()Returns the fully qualified name of this class.
getRateLimit()Returns the maximum number of allowed requests and the window size.
hasMethod()Returns a value indicating whether a method is defined.
hasProperty()Returns a value indicating whether a property is defined.
init()Initializes the object.
loadAllowance()Loads the number of allowed requests and the corresponding timestamp from a persistent storage.
saveAllowance()Saves the number of allowed requests and the corresponding timestamp to a persistent storage.

getRateLimit() ​

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

View source

Arguments ​

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() ​

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

View source

Arguments ​

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() ​

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

View source

Arguments ​

  • $request (yii\web\Request) – The current request
  • $action (yii\base\Action) – The action to be executed
  • $allowance (integer) – The number of allowed requests remaining.
  • $timestamp (integer) – The current timestamp.