middleware(...)` * в начале routes/web.php и docs/ROUTING.md, раздел «Прослойки». */ final class SlowRequestMiddleware { private const DEFAULT_THRESHOLD_MS = 500; public function __invoke(Request $request, callable $next, string $thresholdMs = ''): Response { $threshold = $thresholdMs === '' ? self::DEFAULT_THRESHOLD_MS : max(1, (int) $thresholdMs); $started = microtime(true); $response = $next($request); $elapsed = (microtime(true) - $started) * 1000; if ($elapsed >= $threshold) { (new Logger('slow-requests'))->warning('Медленный запрос раздела', [ 'method' => $request->method, 'path' => $request->path, 'ms' => round($elapsed, 1), ]); } return $response; } }