Created
March 20, 2012 00:43
-
-
Save tiagodavi/2129160 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
//Content-Type do tipo stream | |
header('Content-Type: text/event-stream'); | |
//Sem cash | |
header('Cache-Control: no-cache'); | |
//Inicia uma função | |
function send_msg($msg) { | |
//Envia um json | |
echo 'data:'.json_encode(array('id' => rand(0,100), 'msg' => $msg)); | |
//Descarrega o buffer de saída | |
ob_flush(); | |
flush(); | |
} | |
//Chama a função | |
send_msg('Oi já são '.date('H:i:s').' horas.'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment