maatify/rate-limiter
Composer 安装命令:
composer require 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.
关键字:
README 文档
README
PSR-compliant distributed rate limiting engine supporting Redis, MongoDB, and MySQL with adaptive exponential backoff.
🚀 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?
- 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
| Backend | Driver Type | Use Case |
|---|---|---|
| Redis | Real Driver | High-performance in-memory limits |
| MongoDB | Real Driver | Distributed analytics |
| MySQL | Real Driver | Persistent audit & compliance |
📦 Installation
composer require maatify/rate-limiter
⚡ 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
🧩 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 & Type Safety
- PHPStan Level Max
📄 Documentation
📚 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
🧱 Dependencies Overview
maatify/rate-limiter relies on PSR standards and selected open-source libraries.
🔌 Direct Open-Source Dependencies
| 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 |
🧪 Testing
composer test
Runs:
- Driver consistency tests
- Resolver tests
- Middleware header tests
- Backoff & global limit tests
- Coverage reporting
🪪 License
MIT License © Maatify.dev — Free to use, modify, and distribute with attribution.
👤 Author
Engineered by Mohamed Abdulalim (@megyptm)
Backend Lead & Technical Architect — https://www.maatify.dev
🤝 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:
Built with ❤️ by Maatify.dev — Unified Ecosystem for Modern PHP Libraries
maatify/rate-limiter 适用场景与选型建议
maatify/rate-limiter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 163 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 11 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「redis」 「mysql」 「mongo」 「throttle」 「pdo」 「middleware」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 maatify/rate-limiter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 maatify/rate-limiter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 maatify/rate-limiter 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Microservice RPC through message queues.
The CodeIgniter Redis package
贝嘟分布式缓存扩展
MongoDB extension for the Yii framework
Redis distributed locks for laravel
统计信息
- 总下载量: 163
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 35
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-07