Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php simple sse

<?php
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache'); // recommended to prevent caching of event data.

/**
 * Constructs the SSE data format and flushes that data to the client.
 *
 * @param string $id Timestamp/id of this connection.
 * @param string $msg Line of text that should be transmitted.
 */
function sendMsg($id, $msg) {
  echo "id: $id" . PHP_EOL;
  echo "data: $msg" . PHP_EOL;
  echo PHP_EOL;
  ob_flush();
  flush();
}

$serverTime = time();

sendMsg($serverTime, 'server time: ' . date("h:i:s", time()));
Comment

PREVIOUS NEXT
Code Example
Php :: how to back the page laravel where the scorll is 
Php :: Laravel Secured Password 
Php :: Calculate Math Expression From A String Text With PHP 
Php :: PHP - AJAX and MySQL 
Php :: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given 
Php :: octobercms mail register 
Php :: recursive directory only listing php 
Php :: laravel validation two columns unique 
Php :: how to fetch days old records php mysql 
Php :: php declare variable 
Php :: strpos 
Php :: required_unless laravel 
Php :: phpmailer doesnt work 
Php :: How to check if a session is expired or never was set in php 
Php :: get chmod of directory php 
Php :: In QueryRecorder.php line 22: Argument 2 passed to FacadeIgnitionQueryRecorderQueryRecorder::__construct() must be of the type bool, null given, 
Php :: simple bindings laravel 
Php :: laravel disable logging 
Php :: Unable to do sum and getting same value by using while loop php 
Php :: htaccess rewrite optional parameters 
Php :: drupal form show description 
Php :: php access multidimensional array by string 
Php :: foreach loop in php stack overflow 
Php :: laravel show method 
Php :: confirm popup laravel 
Php :: include JS or Css in wordpress plugin 
Php :: php += 
Php :: firebase realtime database get all data 
Php :: laravel get 
Php :: php regex named groups 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =