Revisions
-
Nils revised this gist
Oct 22, 2015 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ <?php //ob_end_clean(); header('Content-Type: text/event-stream'); header('Cache-Control: no-cache'); //header('Connection: keep-alive'); @@ -9,8 +9,8 @@ echo 'id: ' . uniqid() . PHP_EOL; echo 'data: ' . date("h:i:s", time()) . PHP_EOL; echo PHP_EOL; //ob_flush(); //flush(); sleep(1); } -
Nils revised this gist
Oct 22, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -5,8 +5,8 @@ //header('Connection: keep-alive'); while (true) { //echo "retry: 1000" . PHP_EOL; echo 'id: ' . uniqid() . PHP_EOL; echo 'data: ' . date("h:i:s", time()) . PHP_EOL; echo PHP_EOL; ob_flush(); -
Nils revised this gist
Oct 22, 2015 . 2 changed files with 4 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ <script> if (typeof(EventSource) !== 'undefined') { console.info('Starting connection...'); var source = new EventSource('/stream.php'); source.addEventListener('open', function(e) { console.info('Connection was opened.'); }, false); 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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,9 @@ <?php ob_end_clean(); header('Content-Type: text/event-stream'); header('Cache-Control: no-cache'); //header('Connection: keep-alive'); while (true) { //echo "retry: 1000" . PHP_EOL; -
Nils revised this gist
Oct 22, 2015 . 1 changed file with 5 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,13 @@ <?php ob_end_clean(); while (true) { header('Content-Type: text/event-stream'); header('Cache-Control: no-cache'); //header('Connection: keep-alive'); //echo "retry: 1000" . PHP_EOL; echo 'data: ' . date("h:i:s", time()) . PHP_EOL; echo PHP_EOL; ob_flush(); flush(); -
Nils revised this gist
Oct 22, 2015 . 1 changed file with 2 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,7 @@ <?php while (true) { header('Content-Type: text/event-stream'); header('Cache-Control: no-cache'); echo ' server time: ' . date("h:i:s", time()) . PHP_EOL; echo PHP_EOL; -
Nils created this gist
Oct 22, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ <html> <body> <div id="result"></div> <script> if (typeof(EventSource) !== 'undefined') { console.info('Starting connection...'); var source = new EventSource('/test.php'); source.addEventListener('open', function(e) { console.info('Connection was opened.'); }, false); source.addEventListener('error', function(e) { var txt; switch (event.target.readyState) { // if reconnecting case EventSource.CONNECTING: txt = 'Reconnecting...'; break; // if error was fatal case EventSource.CLOSED: txt = 'Connection failed. Will not retry.'; break; } console.error('Connection error: ' + txt); }, false); source.addEventListener('message', function(e) { document.getElementById('result').innerHTML += e.data + '<br>'; console.log(e.data); }, false); } else { alert('Your browser does not support Server-sent events! Please upgrade it!'); console.error('Connection aborted'); } </script> </body> </html> 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ <?php header('Content-Type: text/event-stream'); header('Cache-Control: no-cache'); header('Connection: keep-alive'); while (true) { echo ' server time: ' . date("h:i:s", time()) . PHP_EOL; echo PHP_EOL; ob_flush(); flush(); sleep(1); }