RateLimit::__construct
Create a limit
Description
public RateLimit::__construct( string $bucket, int $max, int $window )
Creates a limit of $max attempts in $window seconds. Keys are counted apart in each bucket.
Throws \InvalidArgumentException when $bucket is empty or longer than 64 characters, or $max or $window is below 1.
Arguments
| Name | Data type | Default | Remarks |
|---|---|---|---|
| $bucket | string | Name of the limit (1 to 64 characters): 'contact', 'cms-login' | |
| $max | int | Attempts allowed in the window | |
| $window | int | Seconds |
Example
Controller
use Fegg\Tool\RateLimit;
$perHour = new RateLimit('entry', 5, 3600); // 5 an hour
$perDay = new RateLimit('entry-day', 20, 86400); // and 20 a day