<?php
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');

$lastModTime = filemtime('data.json');

while (true) {
    clearstatcache();
    $currentModTime = filemtime('data.json');
    if ($currentModTime > $lastModTime) {
        echo "data: update\n\n";
        ob_flush();
        flush();
        $lastModTime = $currentModTime;
    }
    sleep(2);
}
?>
