PSR-compliant distributed rate limiting engine supporting Redis, MongoDB, and MySQL with adaptive exponential backoff.
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
- 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
| Backend | Driver Type | Use Case |
|---|---|---|
| Redis | Real Driver | High-performance in-memory limits |
| MongoDB | Real Driver | Distributed analytics |
| MySQL | Real Driver | Persistent audit & compliance |
composer require maatify/rate-limiteruse 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
- 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 & Type Safety
- PHPStan Level Max
π Development History & Phase Details
- Phase 1 β Environment Setup
- Phase 2 β Core Architecture
- Phase 3 β Storage Drivers
- Phase 3.1 β Enum Contracts Refactor
- Phase 4 β Resolver & Middleware
- Phase 4.1 β Continuous Integration
- Phase 5 β Exponential Backoff & Global Rate Limit
maatify/rate-limiter relies on PSR standards and selected open-source libraries.
| Library | Purpose |
|---|---|
| psr/http-message | HTTP message interfaces |
| psr/http-server-middleware | PSR-15 middleware |
| psr/http-server-handler | Request handler |
| redis / predis | Redis driver |
| mongodb/mongodb | MongoDB driver |
| phpunit/phpunit | Testing |
| phpstan/phpstan | Static analysis |
composer testRuns:
- Driver consistency tests
- Resolver tests
- Middleware header tests
- Backoff & global limit tests
- Coverage reporting
MIT License Β© Maatify.dev β Free to use, modify, and distribute with attribution.
Engineered by Mohamed Abdulalim (@megyptm)
Backend Lead & Technical Architect β https://www.maatify.dev
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:
Built with β€οΈ by Maatify.dev β Unified Ecosystem for Modern PHP Libraries