Scriptlog Docs

Scriptlog Documentation

Code reference for the Scriptlog codebase

User Tools

Site Tools


scriptlog:lib:core:ratelimiter

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
scriptlog:lib:core:ratelimiter [2026/09/26 09:09] – admin adminscriptlog:lib:core:ratelimiter [2026/09/26 09:34] (current) – admin admin
Line 18: Line 18:
 ======= 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 =======
Line 30: Line 30:
 ======= 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 |
  
  
Line 61: Line 62:
 Constructor Constructor
  
-  ^ Parameter ^ Type ^ Default ^ Description ^ +^  Parameter ^  Type ^  Default ^  Description ^ 
-  | ''$cacheDir'' | ''(untyped)'' | ''null'' | Override cache directory path |+|  ''$cacheDir'' |  ''(untyped)'' |  ''null'' |  Override cache directory path |
  
  
Line 90: Line 91:
 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
Line 109: Line 110:
 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
Line 126: Line 127:
 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
Line 164: Line 165:
 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
Line 180: Line 181:
 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
scriptlog/lib/core/ratelimiter.1790413762.txt.gz · Last modified: by admin