PHP code example of nhphero / throttle

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

    

nhphero / throttle example snippets




$storage = new NhpHero\Throttle\Store\RedisStore( 'throttle_storage_prefix::',[
            'scheme' => config('redis.scheme'),
            'host' => config('redis.host'),
            'port' => config('redis.port'),
            'password' => config('redis.password'),
            'timeout' => config('redis.timeout'),
        ]);
$throttle = new NhpHero\Throttle\Throttle($storage);
//Limit 10 request per 60 seconds
$limit = 10;
$time= 60;
$throttleKey = $_SERVER['REMOTE_ADDR'];
if ($throttle->attempt($throttleKey, $limit, $time)) {
    // allow
} else {
    // deny
}