PHPackages                             maatify/rate-limiter - 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. maatify/rate-limiter

ActiveLibrary[Caching](/categories/caching)

maatify/rate-limiter
====================

Flexible PSR-15 rate limiter supporting Redis, MongoDB, and MySQL via real and fake drivers. Provides multi-strategy algorithms, burst control, sliding window, token bucket, and integration with Maatify Data Repository.

11631[5 PRs](https://github.com/Maatify/rate-limiter/pulls)PHPCI passing

Since Dec 14Pushed 4mo agoCompare

[ Source](https://github.com/Maatify/rate-limiter)[ Packagist](https://packagist.org/packages/maatify/rate-limiter)[ RSS](/packages/maatify-rate-limiter/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (6)Used By (0)

Maatify Rate Limiter
====================

[](#maatify-rate-limiter)

**PSR-compliant distributed rate limiting engine supporting Redis, MongoDB, and MySQL with adaptive exponential backoff.**

[![Maatify.dev](https://camo.githubusercontent.com/bb8bf9ee079d7f823c9d5e94061d1d4c11dc0898e2b1b5cc9a8a7b04d8bfdd7d/68747470733a2f2f7777772e6d6161746966792e6465762f6173736574732f696d672f696d672f6d6161746966795f6c6f676f5f77686974652e737667)](https://camo.githubusercontent.com/bb8bf9ee079d7f823c9d5e94061d1d4c11dc0898e2b1b5cc9a8a7b04d8bfdd7d/68747470733a2f2f7777772e6d6161746966792e6465762f6173736574732f696d672f696d672f6d6161746966795f6c6f676f5f77686974652e737667)

---

[![Version](https://camo.githubusercontent.com/4b09111932030dd6bfedcb307777ff468c740b085e243cdce2631e09871a3d16/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6161746966792f726174652d6c696d697465723f6c6162656c3d56657273696f6e26636f6c6f723d344331)](https://packagist.org/packages/maatify/rate-limiter)[![PHP](https://camo.githubusercontent.com/e46eac8cd3f754b27f8e931dedb31f0244c75feff7b0ee9e1892b02454f8e6df/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6d6161746966792f726174652d6c696d697465723f6c6162656c3d50485026636f6c6f723d373737424233)](https://packagist.org/packages/maatify/rate-limiter)[![PHP Version](https://camo.githubusercontent.com/0751c5c7ed417028d6909f393af80b98d84b224db16e8307c3988e7eefc8ecdb/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e342d626c7565)](https://camo.githubusercontent.com/0751c5c7ed417028d6909f393af80b98d84b224db16e8307c3988e7eefc8ecdb/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e342d626c7565)

[![Build](https://github.com/Maatify/rate-limiter/actions/workflows/ci.yml/badge.svg?label=Build&color=brightgreen)](https://github.com/Maatify/rate-limiter/actions/workflows/ci.yml)

[![Monthly Downloads](https://camo.githubusercontent.com/e833feb338d9e66b7b4ce04a3833baeacd9a0e3156d7b95f4abfcff58d2e1964/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6d6161746966792f726174652d6c696d697465723f6c6162656c3d4d6f6e74686c79253230446f776e6c6f61647326636f6c6f723d303041384538)](https://camo.githubusercontent.com/e833feb338d9e66b7b4ce04a3833baeacd9a0e3156d7b95f4abfcff58d2e1964/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6d6161746966792f726174652d6c696d697465723f6c6162656c3d4d6f6e74686c79253230446f776e6c6f61647326636f6c6f723d303041384538)[![Total Downloads](https://camo.githubusercontent.com/ae94cb4218b19bf135b101c46658961f606f1e5155db984e14528dc5168acb3b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6161746966792f726174652d6c696d697465723f6c6162656c3d546f74616c253230446f776e6c6f61647326636f6c6f723d324141394530)](https://camo.githubusercontent.com/ae94cb4218b19bf135b101c46658961f606f1e5155db984e14528dc5168acb3b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6161746966792f726174652d6c696d697465723f6c6162656c3d546f74616c253230446f776e6c6f61647326636f6c6f723d324141394530)

[![Stars](https://camo.githubusercontent.com/fdf02945d472db89645e2cb8368026b7f85d0b95da584bcc3032c9f45b74dc5b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f4d6161746966792f726174652d6c696d697465723f6c6162656c3d537461727326636f6c6f723d464644343342)](https://camo.githubusercontent.com/fdf02945d472db89645e2cb8368026b7f85d0b95da584bcc3032c9f45b74dc5b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f4d6161746966792f726174652d6c696d697465723f6c6162656c3d537461727326636f6c6f723d464644343342)[![License](https://camo.githubusercontent.com/e802f6e8f7b3acf6b25636324be034f4083d73c5e75ef35fd5c74156e9130fe7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f4d6161746966792f726174652d6c696d697465723f6c6162656c3d4c6963656e736526636f6c6f723d626c756576696f6c6574)](LICENSE)[![Status](https://camo.githubusercontent.com/7ad747e5eefa3aa1040130a413dd5d018f22edbc45638ea213a3376a278e76f6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5374617475732d537461626c652d73756363657373)](https://camo.githubusercontent.com/7ad747e5eefa3aa1040130a413dd5d018f22edbc45638ea213a3376a278e76f6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5374617475732d537461626c652d73756363657373)[![Code Quality](https://camo.githubusercontent.com/3d577f8eb9e13d2e6276ff5955b13ef4b183d47e4e2fec480fd2888b4ed7070a/68747470733a2f2f696d672e736869656c64732e696f2f636f6465666163746f722f67726164652f6769746875622f4d6161746966792f726174652d6c696d697465722f6d61696e3f636f6c6f723d627269676874677265656e)](https://www.codefactor.io/repository/github/Maatify/rate-limiter)

[![PHPStan](https://camo.githubusercontent.com/f85016b73718ab38275b913dafed1c1ce7f287c3c2ec319445bc29011149f408/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d4c6576656c2532304d61782d344538434145)](https://camo.githubusercontent.com/f85016b73718ab38275b913dafed1c1ce7f287c3c2ec319445bc29011149f408/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d4c6576656c2532304d61782d344538434145)[![Coverage](https://camo.githubusercontent.com/fc6bbdbba8d5cca8354564d2278c5a53950d03597959ee98a4d5cc0f768ce7c8/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f75726c3d68747470733a2f2f7261772e67697468756275736572636f6e74656e742e636f6d2f4d6161746966792f726174652d6c696d697465722f6261646765732f636f7665726167652e6a736f6e)](https://camo.githubusercontent.com/fc6bbdbba8d5cca8354564d2278c5a53950d03597959ee98a4d5cc0f768ce7c8/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f75726c3d68747470733a2f2f7261772e67697468756275736572636f6e74656e742e636f6d2f4d6161746966792f726174652d6c696d697465722f6261646765732f636f7665726167652e6a736f6e)

[![Changelog](https://camo.githubusercontent.com/32f7664d004132f7e0fb111b5e01bd7270705d1e7247db502287d51910c04cb9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4368616e67656c6f672d566965772d626c7565)](CHANGELOG.md)[![Security](https://camo.githubusercontent.com/a150750c8b2c6ca6209aa80bdf220d2f0950b984df64c1b859a46ee9152570f3/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53656375726974792d506f6c6963792d696d706f7274616e74)](SECURITY.md)

---

🚀 Overview
==========

[](#-overview)

**Maatify Rate Limiter** is a fully decoupled, PSR-compliant rate-limiting engine designed for:

- Native PHP
- Slim Framework
- Laravel Middleware
- Custom API Gateways

It provides **distributed rate-limiting with adaptive exponential backoff**, unified across:

- **Redis**
- **MongoDB**
- **MySQL**

### Why this library?

[](#why-this-library)

- Zero storage lock-in
- Unified attempt/status/reset API
- Global per-IP rate limit
- Adaptive **Exponential Backoff (2ⁿ)**
- Full PSR-7 / PSR-15 middleware compatibility
- PHPStan Level Max ready

---

✅ Supported Drivers
-------------------

[](#-supported-drivers)

BackendDriver TypeUse CaseRedisReal DriverHigh-performance in-memory limitsMongoDBReal DriverDistributed analyticsMySQLReal DriverPersistent audit &amp; compliance---

📦 Installation
==============

[](#-installation)

```
composer require maatify/rate-limiter
```

---

⚡ Quick Usage
=============

[](#-quick-usage)

```
use Maatify\RateLimiter\Resolver\RateLimiterResolver;
use Maatify\RateLimiter\Enums\RateLimitActionEnum;
use Maatify\RateLimiter\Enums\PlatformEnum;

$resolver = new RateLimiterResolver(['driver' => 'redis']);
$limiter  = $resolver->resolve();

$status = $limiter->attempt(
    '127.0.0.1',
    RateLimitActionEnum::LOGIN,
    PlatformEnum::WEB
);

echo $status->remaining;
```

📘 **Full usage examples (Native, Slim, Laravel, API, Enums, Backoff):**➡️ **[examples/Examples.md](examples/Examples.md)**

---

🧩 Key Features
==============

[](#-key-features)

- **Unified API**: `attempt()`, `status()`, `reset()`
- **Global Per-IP Limit**
- **Adaptive Exponential Backoff**
- **DTO-based Response Model**
- **PSR-7 / PSR-15 Middleware Ready**
- **Custom Enum Contracts**
- **Driver Resolver**
- **Strict Validation &amp; Type Safety**
- **PHPStan Level Max**

---

📄 Documentation
===============

[](#-documentation)

- [**Arabic Documentation**](README-AR.md)
- [**Usage Examples**](examples/Examples.md)
- [**Changelog**](CHANGELOG.md)
- [**Security Policy**](SECURITY.md)

**📚 Development History &amp; Phase Details**- Phase 1 – Environment Setup
- Phase 2 – Core Architecture
- Phase 3 – Storage Drivers
- Phase 3.1 – Enum Contracts Refactor
- Phase 4 – Resolver &amp; Middleware
- Phase 4.1 – Continuous Integration
- Phase 5 – Exponential Backoff &amp; Global Rate Limit

---

🧱 Dependencies Overview
=======================

[](#-dependencies-overview)

`maatify/rate-limiter` relies on PSR standards and selected open-source libraries.

---

🔌 Direct Open-Source Dependencies
---------------------------------

[](#-direct-open-source-dependencies)

LibraryPurposepsr/http-messageHTTP message interfacespsr/http-server-middlewarePSR-15 middlewarepsr/http-server-handlerRequest handlerredis / predisRedis drivermongodb/mongodbMongoDB driverphpunit/phpunitTestingphpstan/phpstanStatic analysis---

🧪 Testing
=========

[](#-testing)

```
composer test
```

Runs:

- Driver consistency tests
- Resolver tests
- Middleware header tests
- Backoff &amp; global limit tests
- Coverage reporting

---

🪪 License
---------

[](#-license)

**[MIT License](LICENSE)**© [Maatify.dev](https://www.maatify.dev) — Free to use, modify, and distribute with attribution.

---

👤 Author
--------

[](#-author)

Engineered by **Mohamed Abdulalim** ([@megyptm](https://github.com/megyptm))
Backend Lead &amp; Technical Architect —

---

🤝 Contributors
--------------

[](#-contributors)

Special thanks to the Maatify.dev engineering team and all open-source contributors. Your efforts help make this library stable, secure, and production-ready.

Before opening a Pull Request, please read:

- [Contributing Guide](CONTRIBUTING.md)
- [Code of Conduct](CODE_OF_CONDUCT.md)

---

 Built with ❤️ by [Maatify.dev](https://www.maatify.dev) — Unified Ecosystem for Modern PHP Libraries

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance50

Moderate activity, may be stable

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity18

Early-stage or recently created project

 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.

### Community

Maintainers

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

---

Top Contributors

[![megyptm](https://avatars.githubusercontent.com/u/33574895?v=4)](https://github.com/megyptm "megyptm (79 commits)")

---

Tags

api-securitybackoffddosmaatifymiddlewaremongodbmysqlphpprotectionpsr15rate-limiterredisthrottling

### Embed Badge

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

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

###  Alternatives

[predis/predis

A flexible and feature-complete Redis/Valkey client for PHP.

7.8k305.7M2.4k](/packages/predis-predis)[snc/redis-bundle

A Redis bundle for Symfony

1.0k39.4M67](/packages/snc-redis-bundle)[react/cache

Async, Promise-based cache interface for ReactPHP

444112.4M40](/packages/react-cache)[wp-media/wp-rocket

Performance optimization plugin for WordPress

7431.3M3](/packages/wp-media-wp-rocket)[illuminate/cache

The Illuminate Cache package.

12835.6M1.4k](/packages/illuminate-cache)[colinmollenhour/php-redis-session-abstract

A Redis-based session handler with optimistic locking

6325.6M14](/packages/colinmollenhour-php-redis-session-abstract)

PHPackages © 2026

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