Skip to content
This repository has been archived by the owner on Mar 6, 2018. It is now read-only.

jitendra-1217/php-valve

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Latest Version

php-valve

Resource or API rate limiting/throttling.

Installation

composer require jitendra/php-valve

Usage Example

// Instantiate limiter that allows 200 attempts per minute.
// Optionally pass custom \Predis\Client client.
$limiter = new \Jitendra\PhpValve\FixedBasic\Redis(60000, 200);
// Attempts passed resource, Optionally pass cost value.
$limiter->attempt('ip:resource');

// [
//     1,              // Allowed?
//     200,            // X-RateLimit-Limit
//     199,            // X-RateLimit-Remaining
//     1516612980700,  // X-RateLimit-Reset (in milliseconds)
//     1516612980700,  // X-RateLimit-RetryAfter (in milliseconds, -1 if not rate limited)
// ]

Implementation

  • Fixed Basic

    (Redis)

    Rate limit attempt to a resource by specifying limit for fixed duration. E.g. 100 attempts per minute.

  • Leaky Bucket

    (Redis)

    Rate limit attempt to a resource via standard leaky bucket logic. E.g. With max burst of 200 and leak rate of 10 requests per second.