Server-Sent Events with libSSE

Basic example

This example shows the server's time


Date:

Source code (Server-side)

  1. <?php
  2. require_once(__DIR__. '/../../vendor/autoload.php');
  3.  
  4. class TimeEvent extends SSEEvent {
  5.         public function update(){
  6.                 return date('l, F jS, Y, h:i:s A');
  7.         }
  8. }
  9.  
  10.         public function check(){
  11.                 return true;
  12.         }
  13. }
  14.  
  15. $sse = new SSE();
  16. $sse->addEventListener('time',new TimeEvent());
  17. $sse->start();
  18. ?>