-
Notifications
You must be signed in to change notification settings - Fork 1
/
demo.php
36 lines (31 loc) · 689 Bytes
/
demo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
/**
* EventSource demo
* @author Zsdroid [[email protected]]
*/
require_once('EventSource.class.php');
$time = date('Y-m-d H:i:s',time());
$progress = range(1,100);
$eventSource = new EventSource;
$lastEventId = $eventSource->getLastEventId();
if($lastEventId == null)
{
$progressId = 1;
}
else if($lastEventId == count($progress))
{
$eventSource->stop();
}
else
{
//progress action
$addProgress = rand(1,20);
$progressId = $lastEventId + $addProgress;
$progressId > count($progress) and $progressId = count($progress);
}
$eventSource
->setLastEventId($progressId)
->setData([$progress[$progressId - 1],$time])
->setEvent('ProgressEvent')
->setRetry(1000)
->output();