PHPackages                             davidfricker/floodgates - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. davidfricker/floodgates

ActiveLibrary

davidfricker/floodgates
=======================

High-speed rate limiter using the leaky bucket algorithm

1.6.1(7y ago)0271MITPHPPHP ^5.3.3 || ^7.0

Since Mar 29Pushed 7y ago1 watchersCompare

[ Source](https://github.com/DavidFricker/Floodgates)[ Packagist](https://packagist.org/packages/davidfricker/floodgates)[ RSS](/packages/davidfricker-floodgates/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)DependenciesVersions (7)Used By (0)

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
-------

[](#install)

Using composer

`composer require DavidFricker/Floodgates`

Usage example
-------------

[](#usage-example)

### Create a rate limiter

[](#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.

```
$UID = md5('127.0.0.1');
$bucket_capacity = 5;
$leak_rate = 60;
$Floodgates = new Floodgates($UID, $bucket_capacity, $leak_rate);
```

### Basic rate limiter usage

[](#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.

```
if (!$Floodgates->addDrop()) {
  die('Rate limit exceeded');
}

// perform the the task that would otherwise be rate limited here
```

### Advanced rate limiter usage

[](#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.

```
$drops = 3;
if (!$Floodgates->addDrop($drops)) {
  die('Rate limit exceeded');
}

// perform the the task that would otherwise be rate limited here
```

Recommendations
---------------

[](#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
-------

[](#methods)

### addDrop

[](#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

[](#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)

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

#### returns

[](#returns-1)

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

### capacityUsed

[](#capacityused)

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

#### returns

[](#returns-2)

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

### isFull

[](#isfull)

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

#### returns

[](#returns-3)

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

### flush

[](#flush)

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

#### returns

[](#returns-4)

void

License
-------

[](#license)

Released under the MIT license.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~85 days

Recently: every ~107 days

Total

6

Last Release

2900d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1b261da4583f1c88fcf9d392ba06c680083a0420c077ce954ec8d0c20d4f398c?d=identicon)[sousdev](/maintainers/sousdev)

---

Top Contributors

[![DavidFricker](https://avatars.githubusercontent.com/u/6656039?v=4)](https://github.com/DavidFricker "DavidFricker (15 commits)")

### Embed Badge

![Health badge](/badges/davidfricker-floodgates/health.svg)

```
[![Health](https://phpackages.com/badges/davidfricker-floodgates/health.svg)](https://phpackages.com/packages/davidfricker-floodgates)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
