Skip to main content
Version: Fegg 5.x

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​

NameData typeDefaultRemarks
$bucketstringName of the limit (1 to 64 characters): 'contact', 'cms-login'
$maxintAttempts allowed in the window
$windowintSeconds

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