libSSE-php icon indicating copy to clipboard operation
libSSE-php copied to clipboard

A very long initial idle time (30s)

Open Defcon0 opened this issue 4 years ago • 5 comments

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

Defcon0 avatar Feb 05 '21 11:02 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?

luizvaz avatar Mar 11 '21 20:03 luizvaz

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.

millsoft avatar Mar 25 '21 12:03 millsoft

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

tonyhhyip avatar May 24 '22 08:05 tonyhhyip

This issue occurs in My LAMP with HTTPS, but it is OK in my Mac laptop without SSL. Weird.

alexwenbj avatar Jun 08 '22 15:06 alexwenbj

@alexwenbj How do you configure the Apache with PHP?

tonyhhyip avatar Jun 19 '23 14:06 tonyhhyip