diff --git a/simulate-nis2.php b/simulate-nis2.php index 83bf325..00282f6 100644 --- a/simulate-nis2.php +++ b/simulate-nis2.php @@ -85,6 +85,7 @@ $S = [ function simLog(string $msg, string $type = 'info'): void { + static $lastHeartbeat = 0; $ts = date('H:i:s'); if (IS_CLI) { $prefix = [ @@ -99,6 +100,12 @@ function simLog(string $msg, string $type = 'info'): void echo "[$ts] {$prefix} {$msg}\n"; flush(); } else { + // Heartbeat SSE ogni 25s — mantiene viva la connessione attraverso proxy (pattern lg231) + $now = time(); + if ($now - $lastHeartbeat >= 25) { + echo ": heartbeat " . $ts . "\n\n"; + $lastHeartbeat = $now; + } echo 'data: ' . json_encode(['t' => $type, 'm' => "[$ts] $msg"]) . "\n\n"; flush(); }