RateLimiter


Check if a specific client has been hitting a specific endpoint too frequently. It is able to use a database MEMORY table, or use local filesystem to allow use without database.

Usage


Use the New(Atlantis\Engine, string, string) factory method to get a fresh tool instance. The UserID can be any string that identifies a user or client. This is usually a User ID, UUID, or HitHash. The EndpointKey can be any string that identifies the current process that is being executed. This is usually something made up specific to describe the current flow, and could even just be __METHOD__ within simple routes.

<?php $Limiter = Atlantis\Systems\RateLimiter\Tool::New($App, $UserID, $EndpointKey);

The HasHitLimitIfNotBump() all-in-one method will return TRUE if this client needs to be throttled, otherwise it will return FALSE and bump that client's hit count up for the next time they hit this resource. The GetWhenExpires() method returns a string describing the timeframe when this user can hit this resource again.

<?php $Limiter = Atlantis\Systems\RateLimiter\Tool::New($App, $UserID, $EndpointKey); if($Limiter->HasHitLimitIfNotBump()) $this->Quit(6, sprintf( 'Too many failed attempts. Please wait %s.', $RateLimit->GetWhenExpires() ));

Application Settings


Atlantis\Systems\RateLimiter\Tool::ConfStorageAPI

string: FQCN of RateLimiter StorageAPI class to use for tracking.

  • Atlantis\Systems\RateLimiter\StorageAPI\Database\Client::class
  • Atlantis\Systems\RateLimiter\StorageAPI\Filesystem\Client::class