Answer the question
In order to leave comments, you need to log in
Why do server SSE messages only come when a connection error occurs?
Why do server messages come all immediately after the initialization of the last error of receiving a message from the server?
date_default_timezone_set('Europe/Moscow');
header('Cache-Control: no-cache\n\n');
header("Content-Type: text/event-stream\n\n");
//header("Connection: keep-alive\n\n");
$length = 20;
while(++$length > 0){
echo "data: 2 $DevID Start Stream !\n\n";
ob_end_flush();
flush();
sleep(5);
}
const evtSource = new EventSource('event.php');
evtSource.onopen = function(open){
console.log('Open EventSource: \n',open);
};
evtSource.onmessage = function(event){
console.log('Work EventSource!!!! \n',event.data);
};
evtSource.onerror = function(err){
console.log('Error EventSource: \n',err);
};
Answer the question
In order to leave comments, you need to log in
I have never used invets, I like websockets more, and even there I used a ready-made library
on the topic - the question is, what kind of web server is it, how does php (cgi or a module) start, because maybe the server is to blame here and not the
ps code if your code is run in php -S then everything works (swears at $DevID by itself and the startup time limit is 30 seconds but continues to work)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question