PHPackages                             godsdev/rate-limiter-mysql - 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. [Caching](/categories/caching)
4. /
5. godsdev/rate-limiter-mysql

ActiveLibrary[Caching](/categories/caching)

godsdev/rate-limiter-mysql
==========================

mysql implementation of godsdev/rate-limiter-interface

v0.1.0(8y ago)118MITPHPPHP &gt;=5.6

Since Jul 7Pushed 8y ago2 watchersCompare

[ Source](https://github.com/GodsDev/rate-limiter-mysql)[ Packagist](https://packagist.org/packages/godsdev/rate-limiter-mysql)[ RSS](/packages/godsdev-rate-limiter-mysql/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (3)Versions (3)Used By (0)

Request rate limiter implementation for MySQL ---------------------------------------------.

Uses

Setting up

```
$conn = \GodsDev\RateLimiter\RateLimiterMysql::createConnectionObj($dbConfig);
$limiter = new \GodsDev\RateLimiter\RateLimiterMysql(
        $rate, //int
        $period, //int
        $userId, //string
        $conn // \PDO connection
);
```

To avoid problems (e.g. count reset after each hit) with differently set time in PHP and MySQL identify it by

```
//@todo put into PHPUnit test instead!
$stmt = $conn->prepare("SELECT NOW();");
$stmt->execute();
$row = $stmt->fetch();
$timestampPhp = date("Y-m-d H:i:s");
if($row[0] !== $timestampPhp){
    error_log("MySQL time {$row[0]} is different from PHP {$timestampPhp}");
}

//in case of identified troubles fix by some code like this
date_default_timezone_set('Europe/Prague');
/** or directly in php.ini
[Date]
date.timezone = "Europe/Prague"
**/
```

Usage

```
//For quota notification calculation
$consumedFromThePast = $limiter->getHits($timestamp);

//Increments usage in time and returns number of hits allowed (compared to increment)
$consumedAmount = $limiter->inc($timestamp, $wantToConsumeAmount);

if ($consumedAmount < 1) {
    // you must wait
} else if ($wantToConsumeAmount > $consumedAmount) {
    // it may partly be executed
} else {
    // green go
}
```

Default table name is `rate_limiter` and it may be changed when calling limiter constructor. Its structure is described in `sql/rate_limiter.sql`.

Testing
=======

[](#testing)

A local file `config.local.php` with a working database connection MUST be created in order to make work `./test-mysql.sh`. Its syntax is:

```
$config["dbConnection"] = array(
    //if you can, use localhost instead of 127.0.0.1 to speed up access on Linux. see a comment in http://php.net/manual/en/pdo.connections.php
    "dsn" => "mysql:dbname=rate_limiter_test;host=localhost",
    "user" => "root",
    "pass" => "",
);
```

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 86.2% 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

Unknown

Total

1

Last Release

3279d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2787653?v=4)[GodsDev](/maintainers/GodsDev)[@GodsDev](https://github.com/GodsDev)

---

Top Contributors

[![tomaskraus](https://avatars.githubusercontent.com/u/3328636?v=4)](https://github.com/tomaskraus "tomaskraus (25 commits)")[![GodsDev](https://avatars.githubusercontent.com/u/2787653?v=4)](https://github.com/GodsDev "GodsDev (4 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/godsdev-rate-limiter-mysql/health.svg)

```
[![Health](https://phpackages.com/badges/godsdev-rate-limiter-mysql/health.svg)](https://phpackages.com/packages/godsdev-rate-limiter-mysql)
```

###  Alternatives

[nikolaposa/rate-limit

General purpose rate limiter implementation.

2731.6M3](/packages/nikolaposa-rate-limit)[beryllium/cachebundle

Provides an interface to Memcache for Symfony2 applications

32136.0k](/packages/beryllium-cachebundle)

PHPackages © 2026

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