Download the PHP package robwittman/leaky-bucket-rate-limiter without Composer

On this page you can find all versions of the php package robwittman/leaky-bucket-rate-limiter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package leaky-bucket-rate-limiter

PSR-7 Leaky Bucket Rate Limiter

This middleware enables API Rate-Limiting based on a Leaky Bucket algorithm.

Usage

To get started, you can easily use composer:

composer require robwittman/leaky-bucket-rate-limiter

Once installed, require the package, apply some settings, and start limiting.

The only required settings to use RateLimiter is a callback and throttle.

Examples

IP Address
Session ID
Request Attribute

Once the bucket has a token to act on, it communicates with Redis to keep track of traffic. If the token is over it's request limit, it will trigger the throttle function passed to the constructor.

Parameters

Callback (required)

The callback argument is called when the Limiter needs a key to check. It passes along the Request object, and can either return an array with a (string) 'token' key, or can return TRUE to skip rate limiting

Throttle (required)

Tell the Limiter how to respond to throttled requests

NOTE All further settings assume callback and throttle parameters are already set

Capacity and Leak

Capacity is the total amount of drips (requests) the bucket may contain. Leak is the amount of drips per second that you want to remove from the bucket

Ignored routes

You can pass an array of routes that you do not want to rate limit. This completely bypasses the rate limit middleware, so they will not have respective headers either

Prefix / Postfix

Provide a prefix / suffix for the bucket key. The key will be stored in Redis as PREFIX.key.SUFFIX

Header

Specify what header to provide, containing Rate Limiting info. Set to false to disable.

Storage

By default, the Rate Limiter will attempt to connect to a local redis instance at http://127.0.0.1:6379, as per Predis\Client().This can be overridden by providing either an array of settings for Predis\Client to connect with, or providing an object with methods get() and set() for storing and retrieving data (mysql, memcached, mongo, etc). If using docker-compose development container, just use redis as the hostname, and container linking will connect it.

Development / Testing

This library comes packaged with a Docker environment for testing and development. If you're not using Docker, you ought to be!

To bootstrap an environment using docker-compose, simply

docker-compose up

This generates a PHP container with source code and packages, running a local dev server. It also provisions and links a Redis container to use as your storage mechanism.

If you're not using docker-compose, or want to implement a different storage system, you can launch a solo container.

The server can be accessed at :8001, and contains a mini app to play around with. Running tests is equally as easy, and is centered around docker


All versions of leaky-bucket-rate-limiter with dependencies

PHP Build Version
Package Version
Requires php Version ^5.5 || ^7.0
predis/predis Version ^1.1
zendframework/zend-diactoros Version ^1.3
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package robwittman/leaky-bucket-rate-limiter contains the following files

Loading the files please wait ....