Skip to content

Instantly share code, notes, and snippets.

@mdmunir
Last active August 29, 2015 14:21
Show Gist options
  • Save mdmunir/d46b50e4741e0f93650b to your computer and use it in GitHub Desktop.
Save mdmunir/d46b50e4741e0f93650b to your computer and use it in GitHub Desktop.
// di file SiteController.php
public function actionMessage()
{
$sse = new \app\components\SSE();
$counter = rand(1, 10);
$t = time();
//$sse->retry(3000);
while ((time() - $t) < 15) {
// Every second, sent a "ping" event.
$curDate = date(DATE_ISO8601);
$sse->event('ping',['time' => $curDate]);
// Send a simple message at random intervals.
$counter--;
if (!$counter) {
$sse->message("This is a message at time $curDate");
$counter = rand(1, 10);
}
$sse->flush();
sleep(1);
}
exit();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment