Created
October 2, 2014 15:53
-
-
Save darfink/90cf692d021a88de9719 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
function eventSourceTest() { | |
header("Content-Type: text/event-stream\n\n"); | |
$counter = rand(1, 10); | |
echo "Bajs $counter eaaa"; | |
while (1) { | |
// Every second, sent a "ping" event. | |
echo "event: ping\n"; | |
$curDate = @date(DATE_ISO8601); | |
echo 'data: {"time": "' . $curDate . '"}'; | |
echo "\n\n"; | |
// Send a simple message at random intervals. | |
$counter--; | |
if (!$counter) { | |
echo 'data: This is a message at time ' . $curDate . "\n\n"; | |
$counter = rand(1, 10); | |
} | |
ob_flush(); | |
flush(); | |
sleep(1); | |
} | |
exit(); | |
} | |
add_action('wp_ajax_test', 'eventSourceTest'); | |
add_action('wp_ajax_nopriv_test', 'eventSourceTest'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment