thamtech/yii2-ratelimiter-advanced
Advanced rate limiter filter for Yii2 using a leaky-bucket algorithm. Define multiple independent limits per action and identifier (IP, user ID, etc.), store allowance/timestamp automatically, customize responses (429, events, headers, callbacks), and support Retry-After.
throttle middleware is simpler and may suffice for basic needs, but this package offers more granular control (e.g., custom strategies, Redis/Memcached support).yii\base\Action, yii\web\Controller) would need abstraction or replacement with Laravel equivalents.predis/predis).yii\web\Request differs from Laravel’s Illuminate\Http\Request. Custom middleware would need to bridge these differences (e.g., extracting IP, path, or headers).yii\caching\Cache interface. Laravel’s Illuminate\Cache is compatible but requires adapters (e.g., Redis, database) to be configured.| Risk Area | Description | Mitigation Strategy |
|---|---|---|
| Framework Mismatch | Yii2-specific components may not work in Laravel without refactoring. | Abstract core logic into framework-agnostic classes; wrap in Laravel middleware. |
| Dependency Conflicts | Potential conflicts with Laravel’s built-in rate limiting or third-party packages (e.g., spatie/rate-limiter). |
Isolate the package in a micro-service or separate module if conflicts arise. |
| Performance Overhead | Redis/Memcached dependency adds latency if not already in use. | Benchmark and compare with Laravel’s native throttle middleware. |
| Maintenance Burden | Package is abandoned (last release 2020). | Fork the repo, update dependencies, and maintain it internally. |
| Key Generation Logic | Custom key logic (e.g., user ID + endpoint) may not align with Laravel’s request lifecycle. | Extend the package’s KeyGenerator interface or create a Laravel-specific adapter. |
throttle or spatie/rate-limiter?
Illuminate\Cache. The package’s yii\caching\Cache interface can be wrapped to use Laravel’s cache drivers.database cache driver (though performance may suffer).RateLimiter class can be wrapped in a Laravel middleware (e.g., app/Http/Middleware/AdvancedRateLimiter.php), integrating with Laravel’s $next($request) pipeline.throttle and spatie/rate-limiter to justify adoption.TokenBucket, SlidingWindow) into framework-agnostic classes.Illuminate\Http\Request → package’s Request).Illuminate\Cache → package’s Cache)./api/public).| Component | Laravel Equivalent | Compatibility Notes |
|---|---|---|
Yii2 yii\base\Action |
Illuminate\Routing\Controller |
Not directly compatible; middleware must handle rate limiting at the HTTP layer. |
Yii2 yii\web\Request |
Illuminate\Http\Request |
Extract IP, path, and headers manually or via adapter. |
Yii2 yii\caching\Cache |
Illuminate\Cache |
Use Laravel’s cache drivers (Redis, database) with a custom adapter. |
| Yii2 Events | Laravel Events (Illuminate\Support\Facades\Event) |
Replace Yii2 event system with Laravel’s or use a lightweight wrapper. |
| Yii2 Modules | Laravel Packages/Service Providers | Package may not support modularity; integrate as a standalone service. |
RateLimiter.Request into the package’s format.Cache facade.KeyGenerator (e.g., UserIdAndIpKeyGenerator).yii2 compatibility, Redis client).Yii::error()) wonHow can I help you explore Laravel packages today?