2017 © Pedro Peláez
 

library rate-limiter-php

A very simple Rate Limiter for PHP

image

perimeter/rate-limiter-php

A very simple Rate Limiter for PHP

  • Thursday, December 3, 2015
  • by bshaffer
  • Repository
  • 4 Watchers
  • 17 Stars
  • 7,299 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 7 % Grown

The README.md

Perimeter RateLimiter

Build Status, (*1)

Rate Limit those APIs!, (*2)

Installation

$ composer.phar require perimeter/rate-limiter-php:dev-develop

This library can be used alongside the perimeter/RateLimitBundle for Symfony2 applications. See the repository for more instructions., (*3)

Get Started

Create your throttler:, (*4)

include_once('vendor/autoload.php');

$redis = new Predis\Client();
$throttler = new Perimeter\RateLimiter\Throttler\RedisThrottler($redis);

Ensure redis is running by executing the redis-server command on the web server where the library is running:, (*5)

$ redis-server

Now you can throttle your users accordingly!, (*6)

// Create a meter ID based on something unique to your user
// In this case we use the IP. This can also be a username,
// company, or some other authenticated property
$meterId = sprintf('ip_address:%s', $_SERVER['REMOTE_ADDR']);
$warnThreshold = 10;
$limitThreshold = 20;

// run the "consume" command
$throttler->consume($meterId, $warnThreshold, $limitThreshold);

if ($throttler->isLimitWarning()) {
    echo "slow down!";
}

if ($throttler->isLimitExceeded()) {
    exit("you have been rate limited");
}

And that's it!, (*7)

The Versions

03/12 2015

dev-develop

dev-develop http://github.com/perimeter/rate-limiter-php

A very simple Rate Limiter for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Courtney Ferguson

api redis perimeter ratelimit api-gateway

31/03 2015

v0.1.1

0.1.1.0 http://github.com/perimeter/rate-limiter-php

A very simple Rate Limiter for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Courtney Ferguson

api redis perimeter ratelimit api-gateway

31/03 2015

v0.1.0

0.1.0.0 http://github.com/perimeter/rate-limiter-php

A very simple Rate Limiter for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Courtney Ferguson

api redis perimeter ratelimit api-gateway