= 0 && $age <= $cacheTtlSeconds) { $serverStatus = $decoded['data']; } } } } if (!is_array($serverStatus)) { $serverStatus = build_server_status($serverStatusTargets); @file_put_contents($cacheFile, json_encode(['ts' => time(), 'data' => $serverStatus], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); } $byUrlNormalized = []; foreach ($serverStatus as $svc) { if (!empty($svc['url']) && is_string($svc['url'])) { $byUrlNormalized[rtrim($svc['url'], '/')] = $svc; } } $payload = json_encode([ 'ts' => time(), 'byUrlNormalized' => $byUrlNormalized, ], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); if ($payload === false) { http_response_code(500); $payload = '{"error":"json_encode_failed"}'; } echo $payload;