How to initialize a JS event to a server with php?

Hello, please tell me how can I implement the server event to the JS.
Yes, you can use sockets, but do not want to.

And if you do so, the JS code is loaded from the server to initialize the event, hence using php on the server to manage JS?
July 2nd 19 at 17:33
1 answer
July 2nd 19 at 17:35
If websocket do not want to try long pooling or periodically poll the server via AJAX or Server-Sent Events

But SSE is not supported in IE, and longruling and Ajax requests can give an even greater load on the server than websocket, depending on the implementation, of course.
On IE at all anyway, thank you now to get acquainted :) - Lavada_Green51 commented on July 2nd 19 at 17:38
Or better tell me, not on php sockets to implement? - Lavada_Green51 commented on July 2nd 19 at 17:41
: In short:

Long pooling is perhaps the most ancient of these, and it is difficult to think of a scenario where it would be justified.
Peck server constant Ajax requests - an extra unnecessary load.
SSE - lightweight and beautiful, is easier than websocket, but only work from the server to the client.
Websocket - realtime messages in both directions, perfectly suited for games for example (agar.io and followers)

In the network there are many other examples of websockets in php, the most famous implementation is perhaps ratchet.

Here is an article with Habra, where bad painted how to write them from scratch https://habrahabr.ru/post/209864/ - Austen.Thompson53 commented on July 2nd 19 at 17:44

Find more questions by tags SocketsAJAXPHPJavaScript