edit fork download
  1. <?php
  2. date_default_timezone_set("America/New_York");
  3. header("Content-Type: text/event-stream\n\n");
  4.  
  5. $counter = rand(1, 10);
  6. while (1) {
  7. // Every second, sent a "ping" event.
  8.  
  9. echo "event: ping\n";
  10. $curDate = date(DATE_ISO8601);
  11. echo 'data: {"time": "' . $curDate . '"}';
  12. echo "\n\n";
  13.  
  14. // Send a simple message at random intervals.
  15.  
  16. $counter--;
  17.  
  18. if (!$counter) {
  19. echo 'data: This is a message at time ' . $curDate . "\n\n";
  20. $counter = rand(1, 10);
  21. }
  22.  
  23. flush();
  24. sleep(1);
  25. }
  26. ?>
Time limit exceeded #stdin #stdout #stderr 5s 25800KB
stdin
Standard input is empty
stdout
event: ping
data: {"time": "2013-10-06T19:47:26-0400"}

event: ping
data: {"time": "2013-10-06T19:47:27-0400"}

event: ping
data: {"time": "2013-10-06T19:47:28-0400"}

event: ping
data: {"time": "2013-10-06T19:47:29-0400"}

event: ping
data: {"time": "2013-10-06T19:47:30-0400"}

event: ping
data: {"time": "2013-10-06T19:47:31-0400"}

event: ping
data: {"time": "2013-10-06T19:47:32-0400"}

event: ping
data: {"time": "2013-10-06T19:47:33-0400"}

event: ping
data: {"time": "2013-10-06T19:47:34-0400"}

data: This is a message at time 2013-10-06T19:47:34-0400

event: ping
data: {"time": "2013-10-06T19:47:35-0400"}

event: ping
data: {"time": "2013-10-06T19:47:36-0400"}

data: This is a message at time 2013-10-06T19:47:36-0400

stderr
PHP Notice:  ob_flush(): failed to flush buffer. No buffer to flush in /home/Oxluqz/prog.php on line 23
PHP Notice:  ob_flush(): failed to flush buffer. No buffer to flush in /home/Oxluqz/prog.php on line 23
PHP Notice:  ob_flush(): failed to flush buffer. No buffer to flush in /home/Oxluqz/prog.php on line 23
PHP Notice:  ob_flush(): failed to flush buffer. No buffer to flush in /home/Oxluqz/prog.php on line 23
PHP Notice:  ob_flush(): failed to flush buffer. No buffer to flush in /home/Oxluqz/prog.php on line 23
PHP Notice:  ob_flush(): failed to flush buffer. No buffer to flush in /home/Oxluqz/prog.php on line 23
PHP Notice:  ob_flush(): failed to flush buffer. No buffer to flush in /home/Oxluqz/prog.php on line 23
PHP Notice:  ob_flush(): failed to flush buffer. No buffer to flush in /home/Oxluqz/prog.php on line 23
PHP Notice:  ob_flush(): failed to flush buffer. No buffer to flush in /home/Oxluqz/prog.php on line 23
PHP Notice:  ob_flush(): failed to flush buffer. No buffer to flush in /home/Oxluqz/prog.php on line 23
PHP Notice:  ob_flush(): failed to flush buffer. No buffer to flush in /home/Oxluqz/prog.php on line 23