'/var/log/nginx/skinbase-performance.log', 'since' => '24h', 'min_requests' => 1, 'top' => 20, 'status' => null, 'uri' => null, 'host' => null, 'slow_ms' => null, ]; foreach (array_slice($argv, 1) as $arg) { if (! str_starts_with($arg, '--')) { fwrite(STDERR, "Unknown argument: {$arg}\n"); exit(2); } [$key, $value] = array_pad(explode('=', substr($arg, 2), 2), 2, '1'); $map = [ 'file' => 'file', 'since' => 'since', 'min-requests' => 'min_requests', 'top' => 'top', 'status' => 'status', 'uri' => 'uri', 'host' => 'host', 'slow-ms' => 'slow_ms', ]; if (! isset($map[$key])) { fwrite(STDERR, "Unknown option: --{$key}\n"); exit(2); } $options[$map[$key]] = $value; } $file = (string) $options['file']; if (! is_readable($file)) { fwrite(STDERR, "Cannot read {$file}\n"); exit(1); } $analyzer = new HttpPerformanceLogAnalyzer(new HttpUriNormalizer()); $result = $analyzer->analyze($file, [ 'since' => $options['since'], 'min_requests' => (int) $options['min_requests'], 'top' => (int) $options['top'], 'status' => $options['status'], 'uri' => $options['uri'], 'host' => $options['host'], 'slow_ms' => $options['slow_ms'] !== null ? (float) $options['slow_ms'] : null, ]); echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES), PHP_EOL;