suhayb/ratelimit

a PHP Package to rate limit an identifier from running code

2.1.0 2019-05-01 19:19 UTC

This package is auto-updated.

Last update: 2024-10-29 05:22:58 UTC


README

General purpose rate limiting for IP Address or any data

Installation

Use the package manager composer to install RateLimit.

composer require suhayb/ratelimit

Usage

<?php


include_once 'vendor/autoload.php';

use \Suhayb\RateLimit\RateLimit;
use \Suhayb\RateLimit\Adapters\ArrayAdapter;

# could be change to any data source compatible with RateLimitQuery interface 
$dataSource = new ArrayAdapter([]);
$rateLimit = new RateLimit(5, $dataSource);

# threw Max Limit Exception on exceeding the limit  
$rateLimit->run("10.11.13.1", function () {
        # do anything
});
    

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT