PHP code example of arash / rlr

1. Go to this page and download the library: Download arash/rlr 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/ */

    

arash / rlr example snippets


use arash\rlr\RLRService;

//default handler is memcache
$limiter = new RLRService(RLRService::HANDLER_REDIS);

//default is 10 request per 60 seconds.
//count of request per window
$limiter->handler->limit = 5;
//time window
$limiter->handler->window = 60;

//list of IPs that you want banned
$limiter->handler->banList = [];

if ($limiter->handler->isRateLimited()) {
    echo 'Rate limit exceeded. Please try again later.';
} else {
    echo 'Request successful.';
}

$behaviors['rlr'] = [
    'class' => 'app\components\RLRFilter',
    'only' => ['array of actions'],
    'except' => ['array of actions'],
    'handlerClass' => RLRService::HANDLER_REDIS, //default handler is memcache
    'limit' => 3, //count of request per window
    'window' => 15, //time window
    'message' => 'your message',
    'banList' => 'list of IPs in array or string that separate with comma'
];