File
File
Rate limiter backend using file-based storage.
class File extends \Hazaar\Util\RateLimiter\Backend\BackendThis backend implementation uses a BTree database to store and manage rate limiting data. It supports configurable file paths and compaction intervals for efficient storage management.
Properties
db
The BTree database instance used for storing rate limiter data.
private BTree $dbindex
private array $indexcreated
public int $createdcompactInterval
The interval (in seconds) after which the database should be compacted.
private int $compactInterval = 3600Methods
__construct
File rate limiter constructor.
public __construct(array $options): voidParameters
| Parameter | Type | Description |
|---|---|---|
$options | array | the options for the file |
shutdown
Performs shutdown operations for the rate limiter backend.
public shutdown(): voidThis method saves any updated rate limit information to the database and, if the compact interval has elapsed since creation, compacts the database to optimize storage.
check
Checks and updates the rate limit information for a given identifier.
public check(string $identifier): voidRetrieves the current rate limit data for the specified identifier, appends the current timestamp to the log, updates the internal index, and returns the updated information.
Parameters
| Parameter | Type | Description |
|---|---|---|
$identifier | string | the unique identifier to check and update rate limit information for |
get
Retrieves and updates the rate limit information for a given identifier.
public get(string $identifier): voidThis method fetches the rate limit log for the specified identifier from the database. It removes any log entries that are outside the configured time window (windowLength). If no log exists for the identifier, it initializes an empty log.
Parameters
| Parameter | Type | Description |
|---|---|---|
$identifier | string | the unique identifier for which to retrieve rate limit information |
remove
Removes the rate limiter entry associated with the given identifier.
public remove(string $identifier): voidParameters
| Parameter | Type | Description |
|---|---|---|
$identifier | string | the unique identifier for the rate limiter entry to remove |
Generated by Hazaar API Doc Generator on Tue, 21 Apr 2026 04:00:24 +0000