Download the PHP package davidfricker/floodgates without Composer

On this page you can find all versions of the php package davidfricker/floodgates. 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 floodgates

Floodgates

This rate limiting class implements the 'leaky bucket' algorithm. Due to the nature of rate limiting standard file based storage is unsuited to the task. For this reason, Floodgates makes use of Redis NoSQL storage that lives in main memory. This means that you are required to have Redis installed to use Floodgates.

Install

Using composer

composer require DavidFricker/Floodgates

Usage example

Create a rate limiter

The following example creates a rate limiting bucket persisted in volatile memory identified by the $UID, which allows 5 requests in any 60 second window.

Basic rate limiter usage

Once you have created a rate limiter object as directed in the previous section simply call the addDrop method and check its return value. If the function returns true then the UID has not exceeded his or her allowed limit and so you may continue.

Advanced rate limiter usage

Some applications will require that a single HTTP call will result in an increment greater than one to the rate limiter, this is often the case when more expensive operations are being performed, such as rendering an image using PHP GD.

To increase the drop count by more than one simply pass the integer you wish to increment by to the addDrop call as shown below.

Recommendations

Consider enabling a swap file to ensure your processes are not killed by the system if you were to receive many requests from differing UIDs.

Methods

addDrop

addDrop($drops = 1) Increases the drop count in the bucket. In real terms this mean it decrements the remaining requests possible in the current window of time.

returns

boolean - true when the UID has enough remaining requests to fulfil this request, false when the request should be rejected due to exceeding the rate limit

capacityLeft

capacityLeft() Fetches the number of drops that can be added to the bucket before it overflows.

returns

int - An integer representing the remaining requests that can be performed before incurring a rate limit

capacityUsed

capacityUsed() Fetches the amount of drops currently in the bucket.

returns

int - An integer representing the number of requests that have been performed in the current time window

isFull

isFull() Fetches the state of the bucket's remaining capacity

returns

boolean - true when a subsequent request to addDrop would return false, i.e. the request limit has been achieved

flush

flush() Reset the bucket contents, i.e. empty all drops from bucket.

returns

void

License

Released under the MIT license.


All versions of floodgates with dependencies

PHP Build Version
Package Version
Requires php Version ^5.3.3 || ^7.0
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 davidfricker/floodgates contains the following files

Loading the files please wait ....