2017 © Pedro Peláez
 

library throttle

Ban identifier after certain amount of requests in a given timeframe.

image

websoftwares/throttle

Ban identifier after certain amount of requests in a given timeframe.

  • Friday, August 16, 2013
  • by Websoftwares
  • Repository
  • 2 Watchers
  • 11 Stars
  • 6,833 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 7 Versions
  • 4 % Grown

The README.md

Throttle (v0.3.3)

Ban identifier after certain amount of requests in a given timeframe., (*1)

Build Status, (*2)

Install composer in your project:, (*3)

curl -s http://getcomposer.org/installer | php

Create a composer.json file in your project root:, (*4)

{
    "require": {
        "websoftwares/throttle": "dev-master"
    }
}

Install via composer, (*5)

php composer.phar install

Usage

Basic usage of the Throttle class to ban an identifier., (*6)

use Websoftwares\Throttle, Websoftwares\Storage\Memcached, Monolog\Logger;

// Ip
$identifier = '$_SERVER["REMOTE_ADDR"]';
// Instantiate class
$throttle = new Throttle(new Logger('throttle'), new Memcached());

if($throttle->validate($identifier)) {
    // Success proceed
} else {
    // Banned
}

Logger

Any logger library that implements the PSR-3 LoggerInterface should work, just create your Logger object and inject it into the Throttle constructor. For example the excellent logging library Monolog., (*7)

Storage

Included is a Memcached example however it is very easy to use some other storage system just implement the StorageInterface and inject that object into the Throttle constructor., (*8)

Caution

Whatever storage system u decide to use, don not store the failed request data into your database, this could lead to a DDOS attack and take your database down., (*9)

Options

U can override the default options by instantiating a Throttle class and pass in an array as the third argument., (*10)

$options = array(
    'banned' => 10, // Ban identifier after 10 attempts. (default 5)
    'logged' => 20, // Log identifier after 20 attempts. (default 10)
    'timespan' => 60 // The timespan for the duration of the ban. (default 86400)
    );

// Instantiate class
$throttle = new Throttle(new Logger('throttle'), new Memcached(), $options);

reset();

This will remove the identifier from the storage., (*11)

$throttle->reset($identifier);

remaining();

This will return an integer that is the remaining attempt(s) available before identifier gets banned., (*12)

$throttle->remaining($identifier);

Memcached

This requires u have the PHP memcached extension installed., (*13)

on Debian/Ubuntu systems for example install like this (requires administrative password)., (*14)

sudo apt-get install php5-memcached

Testing

In the tests folder u can find several tests., (*15)

License

DBAD Public License., (*16)

Acknowledgement

Converted from python example and comments from Forrst.com post., (*17)

The Versions

16/08 2013

dev-master

9999999-dev

Ban identifier after certain amount of requests in a given timeframe.

  Sources   Download

dbad

The Requires

 

The Development Requires

by Boris Verhaaff

security login ip throttle rate limit brute force hammer

16/08 2013

0.3.3

0.3.3.0

Ban identifier after certain amount of requests in a given timeframe.

  Sources   Download

dbad

The Requires

 

The Development Requires

by Boris Verhaaff

security login ip throttle rate limit brute force hammer

15/08 2013

0.3.2

0.3.2.0

Ban identifier after certain amount of requests in a given timeframe.

  Sources   Download

dbad

The Requires

 

The Development Requires

by Boris Verhaaff

security login ip throttle rate limit brute force hammer

15/08 2013

0.3.1

0.3.1.0

Ban identifier after certain amount of requests in a given timeframe.

  Sources   Download

dbad

The Requires

 

The Development Requires

by Boris Verhaaff

security login ip throttle rate limit brute force hammer

15/08 2013

0.3

0.3.0.0

Ban identifier after certain amount of requests in a given timeframe.

  Sources   Download

dbad

The Requires

 

The Development Requires

by Boris Verhaaff

security login ip throttle rate limit brute force hammer

12/08 2013

0.2

0.2.0.0

Ban identifier after certain amount of requests in a given timeframe.

  Sources   Download

dbad

The Requires

 

The Development Requires

by Boris Verhaaff

security login ip throttle rate limit brute force hammer

08/08 2013

0.1

0.1.0.0

Ban ip-adress after certain amount of requests in a given timeframe.

  Sources   Download

dbad

The Requires

 

The Development Requires

by Boris Verhaaff

security login ip throttle rate limit brute force hammer