amirhwsin / php-ratelimit
There is no license information available for the latest version (v1.0.1) of this package.
A lightway php ratelimit package.
v1.0.1
2020-06-16 16:24 UTC
Requires
- php: >=5.3.0
This package is auto-updated.
Last update: 2024-05-13 02:07:40 UTC
README
A lightway php rate limit microframework
This package uses users IP to specify users from each other.
How to use?
Add package to your project with composer like this:
composer require amirhwsin/php-ratelimit
Then run composer autoload:
require_once __DIR__ . '/vendor/autoload.php';
Then add this code where you want to ratelimit:
use RateLimit\Limiter; $tra = new RateLimit\Limiter(); // How many requests do you want to handle? $tra->requests = 30; // In what range? Enter in minutes: 1Min $tra->inRange = 1; // Returns true when user good to go and false if user limited if(!$tra->track()) { echo 'rate limited'; exit; // in case of you want to break users connection with server. }
Storage
This microframework uses json storage similiar to jStorage.
Set storage path
$tra->path = '../storage/rate.limit';
Get storage path/content
$storagePath = $tra->path; fopen($storagePath);