<?php
// heartbeat.php - Keep-alive endpoint
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
header('Connection: keep-alive');
header('X-Accel-Buffering: no');

// Send heartbeat every 2 seconds
while (true) {
    echo "data: heartbeat\n\n";
    if (ob_get_level() > 0) ob_flush();
    flush();
    sleep(2);
}