PHP code example of andrewdyer / predis-request-limiter

1. Go to this page and download the library: Download andrewdyer/predis-request-limiter 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/ */

    

andrewdyer / predis-request-limiter example snippets


// Create new predis client instance
$predis = new Predis\Client();

// Create new limiter instance
$limiter = new Anddye\PredisRequestLimiter\Limiter($predis, 100);
$limiter->setRateLimit(10, 30)
    ->setStorageKey('api:limit:%s');

if ($limiter->hasExceededRateLimit()) {
    // Too many requests has been made, display error message
} else {
    $limiter->incrementRequestCount();
}