Performance: Rate limiting
HIGH IMPACT
Rate limiting controls how often users can make requests, impacting server load and response times.
use Illuminate\Cache\RateLimiter;
public function handle(Request $request, Closure $next) {
$key = $request->ip();
$maxAttempts = 60;
$decayMinutes = 1;
if (app(RateLimiter::class)->tooManyAttempts($key, $maxAttempts)) {
return response('Too many requests', 429);
}
app(RateLimiter::class)->hit($key, $decayMinutes * 60);
return $next($request);
}public function handle(Request $request, Closure $next) {
// No rate limiting
return $next($request);
}| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No rate limiting | N/A | N/A | N/A | [X] Bad |
| Laravel built-in rate limiting middleware | N/A | N/A | N/A | [OK] Good |