fetchHealth(); $lastPurge = $this->lastPurgeRow(); $badge = static function (bool $ok, string $yes, string $no): string { return $ok ? '' . htmlspecialchars($yes) . '' : '' . htmlspecialchars($no) . ''; }; $rows = []; $rows[] = ['SSR delivery', $badge($flagOn, 'ON - pages served from the VPS', 'OFF - SPA as before')]; if ($health === null) { $rows[] = ['SSR server', 'NOT REACHABLE']; } else { $rows[] = ['SSR server', $badge((bool)($health['ok'] ?? false), 'running (' . (int)$health['responseMs'] . ' ms)', 'reports errors')]; $rows[] = ['Release', htmlspecialchars((string)($health['release']['release'] ?? '?')) . ' (commit ' . htmlspecialchars((string)($health['release']['commit'] ?? '?')) . ', built ' . htmlspecialchars($this->fmtDate((string)($health['release']['builtAt'] ?? ''))) . ')']; $rows[] = ['Page cache', (int)($health['cachedPages'] ?? 0) . ' pages / ' . (int)($health['cacheMB'] ?? 0) . ' MB']; } if ($lastPurge !== null) { $rows[] = ['Last purge', htmlspecialchars(date('m-d H:i', (int)$lastPurge['crdate'])) . ' (' . htmlspecialchars((string)$lastPurge['trigger_source']) . ', ' . ($lastPurge['success'] ? 'ok' : 'FAILED') . ', ' . htmlspecialchars(mb_strimwidth((string)$lastPurge['paths'], 0, 60, '…')) . ')']; } if (!$this->purgeService->isConfigured()) { $rows[] = ['Auto purge', 'not configured (var/vitec-ssr-purge.env missing)']; } $html = ''; foreach ($rows as [$label, $value]) { $html .= ''; } $html .= '
' . htmlspecialchars($label) . '' . $value . '
'; $html .= '

Switch: Site Management › Settings › VITEC. Module "VITEC SSR" for purge & protocol.

'; return $html; } public function getOptions(): array { return []; } private function fetchHealth(): ?array { $endpoint = $this->purgeService->getHealthEndpoint(); if ($endpoint === '') { return null; } $start = microtime(true); try { $response = $this->requestFactory->request($endpoint, 'GET', [ 'timeout' => 3, 'connect_timeout' => 2, 'http_errors' => false, ]); if ($response->getStatusCode() !== 200) { return null; } $data = json_decode((string)$response->getBody(), true); if (!is_array($data)) { return null; } $data['responseMs'] = (int)round((microtime(true) - $start) * 1000); return $data; } catch (\Throwable) { return null; } } private function lastPurgeRow(): ?array { try { $qb = $this->connectionPool->getQueryBuilderForTable('tx_vitec_ssrpurgelog'); $row = $qb->select('*')->from('tx_vitec_ssrpurgelog') ->orderBy('uid', 'DESC')->setMaxResults(1) ->executeQuery()->fetchAssociative(); return $row ?: null; } catch (\Throwable) { return null; } } private function fmtDate(string $iso): string { $ts = strtotime($iso); return $ts ? date('Y-m-d H:i', $ts) : '?'; } }