| Server IP : 127.0.0.1 / Your IP : 192.168.99.1 Web Server : Apache/2.4.35 (Win64) OpenSSL/1.1.1b mod_fcgid/2.3.9 System : Windows NT WIN-JEJMB9EN0L0 10.0 build 14393 (Windows Server 2016) AMD64 User : Administrator ( 0) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /wamp/www/sipapbd_2020_pergeseran2/assets/libSSE/ |
Upload File : |
<?php
/*
* @package libSSE-php
* @author Licson Lee <licson0729@gmail.com>
* @description A PHP library for handling Server-Sent Events (SSE)
*/
/*
* @class SSEUtils
* @description Helper class
*/
class SSEUtils {
/*
* @method SSEUtils::sseData
* @param $str the data to be processed
* @description Make strings SSE friendly (For internal use only)
*/
static public function sseData($str){
return 'data: '.str_replace("\n","\ndata: ",$str);
}
/*
* @method SSEUtils::sseBlock
* @param $id the event ID
* @param $event the event name
* @param $data the event data
* @description method for output a SSE data block (For internal use only)
*/
static public function sseBlock($id,$event,$data){
echo 'id: '.$id."\n";
if($event != '') echo 'event: '.$event."\n";
echo self::sseData($data)."\n\n";//send the data
}
/*
* @method SSEUtils::time_mod
* @param $start the start timestamp
* @param $n the time interval
* @description Calculate the modulus of time
*/
static public function time_mod($start,$n){
return (time() - $start) % $n;
}
/*
* @method SSEUtils::time_diff
* @param $start the start timestamp
* @description Calculate the time difference
*/
static public function time_diff($start){
return time() - $start;
}
}