| Next revision | Previous revision |
| scriptlog:lib:core:ratelimiter [2026/09/26 09:09] – admin admin | scriptlog:lib:core:ratelimiter [2026/09/26 09:34] (current) – admin admin |
|---|
| ======= Docblock Metadata ======= | ======= Docblock Metadata ======= |
| |
| ^ Tag ^ Value ^ | ^ Tag ^ Value ^ |
| | ''@category'' | Core Class | | | ''@category'' | Core Class | |
| | ''@author'' | Blogware Team | | | ''@author'' | Blogware Team | |
| | ''@license'' | MIT | | | ''@license'' | MIT | |
| | ''@version'' | 1.0 | | | ''@version'' | 1.0 | |
| |
| ======= Inheritance ======= | ======= Inheritance ======= |
| ======= Constants (2) ======= | ======= Constants (2) ======= |
| |
| ^ Visibility ^ Name ^ Value ^ Line ^ | ^ Visibility ^ Name ^ Value ^ Line ^ |
| | ''-'' | ''DEFAULT_LIMIT'' | ''60;'' | 26 | | | ''-'' | ''DEFAULT_LIMIT'' | ''60;'' | 26 | |
| | ''-'' | ''DEFAULT_WINDOW'' | ''60;'' | 31 | | | ''-'' | ''DEFAULT_WINDOW'' | ''60;'' | 31 | |
| |
| ======= Properties (0) ======= | ======= Properties (1) ======= |
| |
| //None declared.// | ^ Visibility ^ Type ^ Name ^ Default ^ Line ^ |
| | | ''private'' | ''(untyped)'' | ''$cacheDir'' | | 38 | |
| |
| ======= Methods (8) ======= | ======= Methods (8) ======= |
| |
| ^ Visibility ^ Method ^ Summary ^ Line ^ | ^ Visibility ^ Method ^ Summary ^ Line ^ |
| | public | ''__construct()'' | Constructor | 45 | | | public | ''__construct()'' | Constructor | 45 | |
| | private | ''ensureCacheDir()'' | Ensure the cache directory exists and is writable | 56 | | | private | ''ensureCacheDir()'' | Ensure the cache directory exists and is writable | 56 | |
| | public | ''check()'' | Check if the current request exceeds the rate limit | 72 | | | public | ''check()'' | Check if the current request exceeds the rate limit | 72 | |
| | private | ''readTimestamps()'' | Read timestamps from file, filtering out expired ones | 119 | | | private | ''readTimestamps()'' | Read timestamps from file, filtering out expired ones | 119 | |
| | private | ''writeTimestamps()'' | Write timestamps to file | 148 | | | private | ''writeTimestamps()'' | Write timestamps to file | 148 | |
| | private | ''getClientKey()'' | Generate a unique key for the current client | 167 | | | private | ''getClientKey()'' | Generate a unique key for the current client | 167 | |
| | public | ''reset()'' | Reset rate limit for a specific key | 178 | | | public | ''reset()'' | Reset rate limit for a specific key | 178 | |
| | public | ''cleanup()'' | Clean up expired rate limit files | 196 | | | public | ''cleanup()'' | Clean up expired rate limit files | 196 | |
| |
| |
| Constructor | Constructor |
| |
| ^ Parameter ^ Type ^ Default ^ Description ^ | ^ Parameter ^ Type ^ Default ^ Description ^ |
| | ''$cacheDir'' | ''(untyped)'' | ''null'' | Override cache directory path | | | ''$cacheDir'' | ''(untyped)'' | ''null'' | Override cache directory path | |
| |
| |
| Check if the current request exceeds the rate limit | Check if the current request exceeds the rate limit |
| |
| ^ Parameter ^ Type ^ Default ^ Description ^ | ^ Parameter ^ Type ^ Default ^ Description ^ |
| | ''$key'' | ''(untyped)'' | ''null'' | Unique identifier (default: client IP) | | | ''$key'' | ''(untyped)'' | ''null'' | Unique identifier (default: client IP) | |
| | ''$limit'' | ''(untyped)'' | ''self::DEFAULT_LIMIT'' | Maximum requests allowed in the window | | | ''$limit'' | ''(untyped)'' | ''self::DEFAULT_LIMIT'' | Maximum requests allowed in the window | |
| | ''$window'' | ''(untyped)'' | ''self::DEFAULT_WINDOW'' | Window size in seconds | | | ''$window'' | ''(untyped)'' | ''self::DEFAULT_WINDOW'' | Window size in seconds | |
| | ''$namespace'' | ''(untyped)'' | '''''' | Optional counter namespace (e.g. 'read' vs 'write') | | | ''$namespace'' | ''(untyped)'' | '''''' | Optional counter namespace (e.g. 'read' vs 'write') | |
| |
| **Returns:** ''(none declared)'' — array Result with limit, remaining, reset, retry_after, allowed | **Returns:** ''(none declared)'' — array Result with limit, remaining, reset, retry_after, allowed |
| Read timestamps from file, filtering out expired ones | Read timestamps from file, filtering out expired ones |
| |
| ^ Parameter ^ Type ^ Default ^ Description ^ | ^ Parameter ^ Type ^ Default ^ Description ^ |
| | ''$file'' | ''(untyped)'' | //required// | File path | | | ''$file'' | ''(untyped)'' | //required// | File path | |
| | ''$windowStart'' | ''(untyped)'' | //required// | Earliest valid timestamp | | | ''$windowStart'' | ''(untyped)'' | //required// | Earliest valid timestamp | |
| |
| **Returns:** ''(none declared)'' — array Valid timestamps | **Returns:** ''(none declared)'' — array Valid timestamps |
| Write timestamps to file | Write timestamps to file |
| |
| ^ Parameter ^ Type ^ Default ^ Description ^ | ^ Parameter ^ Type ^ Default ^ Description ^ |
| | ''$file'' | ''(untyped)'' | //required// | File path | | | ''$file'' | ''(untyped)'' | //required// | File path | |
| | ''$timestamps'' | ''(untyped)'' | //required// | Timestamps to write | | | ''$timestamps'' | ''(untyped)'' | //required// | Timestamps to write | |
| | ''$windowStart'' | ''(untyped)'' | //required// | Earliest valid timestamp | | | ''$windowStart'' | ''(untyped)'' | //required// | Earliest valid timestamp | |
| |
| **Returns:** ''(none declared)'' — void | **Returns:** ''(none declared)'' — void |
| Reset rate limit for a specific key | Reset rate limit for a specific key |
| |
| ^ Parameter ^ Type ^ Default ^ Description ^ | ^ Parameter ^ Type ^ Default ^ Description ^ |
| | ''$key'' | ''(untyped)'' | ''null'' | Unique identifier | | | ''$key'' | ''(untyped)'' | ''null'' | Unique identifier | |
| |
| **Returns:** ''(none declared)'' — bool | **Returns:** ''(none declared)'' — bool |
| Clean up expired rate limit files | Clean up expired rate limit files |
| |
| ^ Parameter ^ Type ^ Default ^ Description ^ | ^ Parameter ^ Type ^ Default ^ Description ^ |
| | ''$maxAge'' | ''(untyped)'' | ''3600'' | Maximum age in seconds before file is considered stale | | | ''$maxAge'' | ''(untyped)'' | ''3600'' | Maximum age in seconds before file is considered stale | |
| |
| **Returns:** ''(none declared)'' — int Number of files cleaned | **Returns:** ''(none declared)'' — int Number of files cleaned |