Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel server sent events

$loopTime = 1;
$response = new StreamedResponse(static function () use ($loopTime) {
    while (true) {
      	$data = [
        	'name' => 'Taylor Otwell'
        ]
      
      	echo "event: sse
";
      	echo "data: " . json_encode($data) . "

";
        echo str_pad('', 4096) . "
";
      
    	ob_flush();
      	flush();
      	sleep($loopTime);

      	if (connection_aborted()) {
        	break;
      	}
    }
    ob_end_flush();
}
                                 
$response->headers->set('Content-Type', 'text/event-stream');
$response->headers->set('Cache-Control', 'no-cache');
return $response;
Comment

PREVIOUS NEXT
Code Example
Php :: php artisan orderByDesc 
Php :: how validate the value of object in arraye in laravel 
Php :: redirect to attempting url after login laravel 
Php :: boot add schema in laravel 
Php :: laravel update return updated row, laravel update return 
Php :: send data from php to python 
Php :: laravel collection push 
Php :: run xampp application on windows startup 
Php :: carbon subdays 
Php :: php regex match numbers only 
Php :: laravel create model and migration 
Php :: php postgresql number of rows 
Php :: target class admin homecontroller does not exist laravel 8 
Php :: hash password laravel 
Php :: set cookie one day php 
Php :: Extract Numbers From a String in PHP 
Php :: sum of multidimensional array in php 
Php :: php get part of string 
Php :: json to php array 
Php :: remove string after comma in php 
Php :: php cookie 
Php :: get from table laravel 
Php :: display image from database in laravel 
Php :: doctrine orm get all 
Php :: laravel get last id 
Php :: php unlink 
Php :: php file download from url 
Php :: Your system folder path does not appear to be set correctly. Please open the following file and correct this: index.php 
Php :: get_categories not__in 
Php :: php opendir 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =