PHP code example of amirhwsin / php-ratelimit
1. Go to this page and download the library: Download amirhwsin/php-ratelimit library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
amirhwsin / php-ratelimit example snippets
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.
}
$tra->path = '../storage/rate.limit';
$storagePath = $tra->path;
fopen($storagePath);
shell
composer