Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.
/ RateLimiter Public archive

RateLimiter class for enforcing rate limits on user requests.

License

Notifications You must be signed in to change notification settings

oxcakmak/RateLimiter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

RateLimiter

RateLimiter class for enforcing rate limits on user requests.

Support Me

This software is developed during my free time and I will be glad if somebody will support me.

Everyone's time should be valuable, so please consider donating.

https://buymeacoffee.com/oxcakmak

Installation

require_once 'RateLimiter.php';

Usage

try {
    $limiter = new RateLimiter(5, 60); // Allow 5 requests per minute

    if (!$limiter->check()) {
        http_response_code(429); // Set response code to "Too Many Requests"
        echo "You have exceeded the rate limit. Please try again later.";
        exit; // Stop script execution
    }

    // Your application logic here...

} catch (RuntimeException $e) {
    // Handle session-related errors
    http_response_code(500);
    echo "Internal Server Error: " . $e->getMessage();
    exit;
}

About

RateLimiter class for enforcing rate limits on user requests.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages