A very long initial idle time (30s)
Hello,
I implemented your example for my symfony 4.4 project. It works but unfortunately, I have to wait about 30s before the first console.log()'s happen in the client.
Is this a known issue?
Here's my controller:
$sse = new SSE(); //create a libSSE instance
$sse->addEventListener('event_name', new YourEventHandler());//register your event handler
$sse->start();//start the event loop
// Add your event listener
return $sse->createResponse();
class YourEventHandler implements Event {
public function update(){
//Here's the place to send data
return 'Hello, world!';
}
public function check(){
//Here's the place to check when the data needs update
return true;
}
}
js:
var sse = new EventSource('http://www.monitor.hundh.hhdev/sse.php');
sse.addEventListener('event_name',function(e){
var data = e.data;
//handle your data here
console.log(data);
},false);
When using the w3c example, it works quickly, so I guess I misconfigurated something?
Thanks in advance!
Bye Defcon0
Remember this: Rasmus Lerdorf : PHP Frameworks all suck! Though everyone needs a framework, just not a general purpose framework
SSE needs quick response and minimal resource load. Going SSE over Symfony Framework on your Project takes a lot to load. Why don't you write a simple PHP file and use a NGNIX/APACHE rewrite rule to simplify?
I have the same problem. The requests stays in "pending", then after ~60 seconds console.log starts to log. Here is an example:
https://ttprivatenew.s3.amazonaws.com/pulse/pits-michel/attachments/16360562/TinyTake25-03-2021-01-17-06.mp4
60 / 30 seconds sounds like a some php config issue.
When I use $sse->exec_limit = 10, it will reconnect after 10 seconds and the logging works fine.
Symfony HTTP Foundation is used to leverage the abstraction of HTTP request and response which is not available in PHP itself, it should not be idle for a long time. If you still facing this problem, you should check the proxy buffer in nginx
This issue occurs in My LAMP with HTTPS, but it is OK in my Mac laptop without SSL. Weird.
@alexwenbj How do you configure the Apache with PHP?