How to use a long poll (preferably without a comet or node.js)?

Suppose I synchronize the text on an HTML page stored in localStorage from computer A to computer B. When a user edits the text on computer A, I send a request to the server and tell what text was changed. Is there a way I can get the server to tell computer B that the new text, without computer B, should continue to check? I read about comets, but I try not to use any libraries. Is there any way? Also, if you intend to offer a comet, could you give a simple example using normal JavaScript and comets?

I had an idea, but I don’t know if it will work. On computer B, I send the request once and let the server file defer the response until new text appears. This way, it will look like a long poll, but the request will ultimately be a timeout. If there was a way to set the timeout so that it never was, it would be much easier. So who has any ideas?

PS- I want to use only JavaScript and PHP and try to avoid using libraries. However, if you know of a library that can do this using JS and PHP, please tell me anyway.

In addition, I know that there were such questions, but the answers I found there were unsatisfactory.

Oh, and if anyone knows how chat works here, could you tell me this?

tl; dr: I want to send a request from the server to an HTML page or send an HTML request to one request, which is saved until the corresponding response is created.

+6
source share
1 answer

Comet is an implementation of long polls.

The problem is that the host should keep all resources available for all open requests. Servers must be carefully configured so that it runs smoothly under load. This is not an out of the box solution.

Another drawback is that each user must be tied to a specific server, so there is no easy way to load balance requests.

Frequent use of periodic polling is the best choice.

+2
source

Source: https://habr.com/ru/post/894389/


All Articles