2017 © Pedro Peláez
 

library rate-limit

Standalone component that facilitates rate-limiting functionality. Also provides a middleware designed for API and/or other application endpoints.

image

nikolaposa/rate-limit

Standalone component that facilitates rate-limiting functionality. Also provides a middleware designed for API and/or other application endpoints.

  • Wednesday, October 25, 2017
  • by nikolaposa
  • Repository
  • 5 Watchers
  • 13 Stars
  • 2,213 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 8 Versions
  • 31 % Grown

The README.md

Rate Limit

Build Scrutinizer Code Quality Code Coverage Latest Stable Version PDS Skeleton, (*1)

General purpose rate limiter that can be used to limit the rate at which certain operation can be performed. Default implementation uses Redis as backend., (*2)

Installation

The preferred method of installation is via Composer. Run the following command to install the latest version of a package and add it to your project's composer.json:, (*3)

composer require nikolaposa/rate-limit

Usage

Terminating rate limiter, (*4)

use RateLimit\Exception\LimitExceeded;
use RateLimit\Rate;
use RateLimit\RedisRateLimiter;
use Redis;

$rateLimiter = new RedisRateLimiter(Rate::perMinute(100), new Redis());

$apiKey = 'abc123';

try {
    $rateLimiter->limit($apiKey);

    //on success
} catch (LimitExceeded $exception) {
   //on limit exceeded
}

Silent rate limiter, (*5)

use RateLimit\Rate;
use RateLimit\RedisRateLimiter;
use Redis;

$rateLimiter = new RedisRateLimiter(Rate::perMinute(100), new Redis());

$ipAddress = '192.168.1.2';
$status = $rateLimiter->limitSilently($ipAddress);

echo $status->getRemainingAttempts(); //99

Practical usage with configuring multiple rate limiting strategies in a project, (*6)

use RateLimit\Rate;
use RateLimit\RedisRateLimiter;

$container->set('rate_limiter.api', new RedisRateLimiter(Rate::perSecond(10), $container->get('redis')));
$container->set('rate_limiter.videos', new RedisRateLimiter(Rate::perDay(5), $container->get('redis')));

Supported drivers

Credits

License

Released under MIT License - see the License File for details., (*7)

The Versions

25/10 2017

dev-master

9999999-dev

Standalone component that facilitates rate-limiting functionality. Also provides a middleware designed for API and/or other application endpoints.

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware rate limit

25/10 2017

1.0.1

1.0.1.0

Standalone component that facilitates rate-limiting functionality. Also provides a middleware designed for API and/or other application endpoints.

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware rate limit

14/02 2017

1.0.0

1.0.0.0

Standalone component that facilitates rate-limiting functionality. Also provides a middleware designed for API and/or other application endpoints.

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware rate limit

09/02 2017

0.4.0

0.4.0.0

Standalone component that facilitates rate-limiting functionality. Also provides a middleware designed for API and/or other application endpoints.

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware rate limit

08/02 2017

dev-feature/autonomous-rate-limiter

dev-feature/autonomous-rate-limiter

Rate limiting middleware designed for API and/or other application endpoints.

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware rate limit

04/02 2017

0.3.0

0.3.0.0

Rate limiting middleware designed for API and/or other application endpoints.

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware rate limit

27/01 2017

0.2.0

0.2.0.0

Rate limiting middleware designed for API and/or other application endpoints.

  Sources   Download

MIT

The Requires

 

The Development Requires

22/01 2017

0.1.0

0.1.0.0

Rate limiting middleware designed for API and/or other application endpoints.

  Sources   Download

MIT

The Requires

 

The Development Requires