关于该软件包最新版本(0.0.2)的许可信息不可用。

0.0.2 2024-02-06 10:00 UTC

This package is auto-updated.

Last update: 2024-09-06 11:33:27 UTC


README

Packagist Dependency Version Packagist Dependency Version Packagist Version

安装

composer require antikirra/rate-limiter

基本用法

<?php

use Antikirra\RateLimiter;

require __DIR__ . '/vendor/autoload.php';

$redis = new Redis();
$redis->connect('127.0.0.1');

// maximum of three requests per minute
$limiter = new RateLimiter($redis, "signin_by_ip{$_SERVER['REMOTE_ADDR']}", 3, 60, 0.75);

$result = $limiter->check(); // returns the actual counter value without any side effects
echo $result->getCount(); // (int) actual counter value
print_r($result->isPassed()); // (bool) true - it's okay, false - flood has been detected!!!

$result = $limiter->hit(); // increments the counter value, returning the result of the check
echo $result->getCount(); // (int) updated counter value
print_r($result->isPassed()); // (bool) true - it's okay, false - flood has been detected!!!
print_r($result->isFailed()); // (bool) true - flood has been detected!!!, false - it's okay

$limiter->reset(); // (void) resets counters to zero