I’ve been looking at various techniques for pushing data from a server to a Flutter Web app, and Websockets and SSE (Server-Sent Events) are unfortunately out of the question.

So, I thought about using long polling instead. I understand it is more resource wasting than SSE and Websockets because data can only be sent once, and then a new HTTP connection must be established. But in my case the data would be sent only very rarely – sometimes as rarely as a few times per day, or at most a few times per hour. The client app is meant to be running 24/7 as a type of monitoring system, and the number of concurrent clients would most likely be at most a few hundred, and definitely not more than a few thousand.

Two questions come to mind regarding this:

  1. If data is only sent very rarely, wouldn’t long polling be almost as efficient as SSE? I mean, tearing down and setting up an HTTP connection a few times per hour per client doesn’t seem like a big deal? Or is there other overhead involved in long polling compared to SSE?

  2. Regardless of using SSE or long polling, wouldn’t I need to have one instance of the server app (a PHP script) running per connection? The server script needs to check for changes periodically and then sleep for about 5-10 seconds, and I presume I must do this in an “infinite” (until the connection is closed and the script instance terminated) loop? It seems to me that this would be quite resource intensive in itself, so if the server script works the same for both SSE and long-polling, the only difference in resource use would be the connect/disconnect of HTTP connections, right?

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *