Created
July 2, 2012 21:38
-
-
Save marcmartino/3035875 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
header('Content-Type: text/event-stream'); | |
header('Cache-Control: no-cache'); // recommended to prevent caching of event data. | |
/** | |
* Constructs the SSE data format and flushes that data to the client. | |
* | |
* @param string $id Timestamp/id of this connection. | |
* @param string $msg Line of text that should be transmitted. | |
*/ | |
function sendMsg($id, $msg) { | |
echo "id: $id" . PHP_EOL; | |
echo "data: $msg" . PHP_EOL; | |
echo PHP_EOL; | |
ob_flush(); | |
flush(); | |
} | |
$serverTime = time(); | |
sendMsg($serverTime, 'server time: ' . date("h:i:s", time())); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment