bedrockstreaming/rate-limit-bundle
Pros:
#[RateLimit], #[GraphQLRateLimit]) for declarative configuration, aligning with modern PHP attribute-based routing.Cons:
symfony/bundle and symfony/dependency-injection).ServiceProvider to register the bundle’s services.predis/predis or symfony/cache for distributed rate limiting.webonyx/graphql-php (not Laravel-native).throttle middleware.#[RateLimit]) may not align perfectly with Symfony’s (e.g., namespace conflicts).throttle middleware, or must they coexist?spatie/rate-limiter).throttle).limit_by_route: false (global limit) first.x-rate-limit-*) appear in responses.namespace App\Http\Middleware;
use Bedrock\Bundle\RateLimitBundle\RateLimitListener;
class RateLimitMiddleware {
public function __construct(private RateLimitListener $listener) {}
public function handle($request, Closure $next) {
$this->listener->onKernelRequest($request->toSymfonyRequest());
return $next($request);
}
}
app/Http/Kernel.php.bedrock_rate_limit.yaml:
bedrock_rate_limit:
storage: redis://127.0.0.1:6379
webonyx/graphql-php and configure the #[GraphQLRateLimit] attribute.EventDispatcher with Laravel’s Illuminate\Events\Dispatcher.Attribute class.throttle middleware (may double-count requests).RateLimit classes.limit_by_route: true).display_headers: true).x-rate-limit-*) aid debugging.x-rate-limit-until headers for anomalies.| Scenario | Impact | Mitigation |
|---|---|---|
| Redis failure | Rate limits disabled | Fallback to in-memory (with warnings). |
| Attribute parsing error | Routes bypass rate limits | Validate annotations in CI. |
| High traffic burst | Throttling too aggressive | Adjust period (e.g., 30s instead of 600s). |
| IP spoofing | Attackers bypass limits | Combine with throttle middleware. |
| Bundle update conflicts | Breaking changes in Laravel | Pin version in composer.json. |
How can I help you explore Laravel packages today?