ThrottlerInterface
in
Expected behavior of a Throttler
Table of Contents
Methods
- check() : bool
- Restricts the number of requests made by a single key within a set number of seconds.
- getTokenTime() : int
- Returns the number of seconds until the next available token will be released for usage.
Methods
check()
Restricts the number of requests made by a single key within a set number of seconds.
public
check(string $key, int $capacity, int $seconds, int $cost) : bool
Example:
if (! $throttler->checkIPAddress($request->ipAddress(), 60, MINUTE)) { die('You submitted over 60 requests within a minute.'); }
Parameters
- $key : string
-
The name to use as the "bucket" name.
- $capacity : int
-
The number of requests the "bucket" can hold
- $seconds : int
-
The time it takes the "bucket" to completely refill
- $cost : int
-
The number of tokens this action uses.
Return values
boolgetTokenTime()
Returns the number of seconds until the next available token will be released for usage.
public
getTokenTime() : int