PHP code example of phpsoftbox / rate-limiter

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

    

phpsoftbox / rate-limiter example snippets


$result = $limiter->hit($key, 5, 300);
if (!$result->allowed) {
    // 429, Retry-After: $result->retryAfterSeconds
}

if ($credentialsValid) {
    $limiter->reset($key);
}

$limiter = new SimpleCacheRateLimiter($cache, $clock);
$limiter = new RedisRateLimiter($redis, $clock);
$limiter = new AtomicStoreRateLimiter($store, $clock);

$limiter = new RedisRateLimiter($phpRedisClient);

$key = $normalizer->normalize($rawKey, 'node_api');