« Back to Index

server-sent events

View original Gist on GitHub

Tags: #php

server-sent-event.php

<?php
header("Content-Type: text/event-stream");
while(true) {
    echo "Event: server-time\n";
    $time = time();
    echo "data: $time\n";
    echo "\n";
    flush();
    sleep(3);
}
?>