Opposite AJAX

Is there a way to implement a server-initiated message that refreshes a page (rather than an entire page) in PHP?

In other words, is there a way to implement “modified” AJAX where the server initiates the connection?

+4
source share
6 answers

You are probably thinking of push technologies such as COMET or long polling. See http://en.wikipedia.org/wiki/Comet_ (programming) and http://en.wikipedia.org/wiki/Long_polling#Long_polling

+4
source

You cannot open a server connection for a client. You need to do some kind of polling from client to server. You can look into COMET or simply poll the server after a set period of time to check for new content.

+2
source

You need to look at what is called a multitude of names such as Comet, AJAX Push, Server Push, etc.

http://en.wikipedia.org/wiki/Comet_(programming ))

It keeps the HTTP connection open so that it can communicate with the server at some point in time.

0
source

Yes, you can use a long HTTP poll or web socket in some new browsers (Chrome).

0
source

You are talking about a “reverse ajax” and sometimes a “comet”. Reverse ajax is not part of the http specification, it's a bit of a hack. Essentially, this is because the HTTP request remains open when the server sends the responses back. This is not crazy, although, frankly, 99% of the applications are probably not worth the stress. You will need a comet server to process and manage all open connections. Seriously, consider automatic updates to regular ajax calls or something like that.

0
source

You need SSE (events sent by the server). The only drawback is that it is not yet supported by any of IE, so you will probably need to implement some discovery functions (with, for example, modernizr.js) and use either a long poll or SSE , depending on which whether your browser is SSE (or just use SSE polyfill , there are many thanks).
Why would you probably want to implement both methods instead of going with a well-supported long poll ? Server-sent events and polling .

Here is a tutorial on PHP implementation: http://www.w3schools.com/html/html5_serversentevents.asp

And a good explanation of what SSE gives:

HTML5 introduced an API for working with server events. The basic idea of ​​SSE is simple: a web page subscribes to an event source on a web server that sends updates streams. The web page does not need to constantly check the server to check for updates (as was done with the AJAX poll) - they automatically appear. Note that the client-side script can only listen for updates, it cannot publish anything (compare this to web sockets where the client can subscribe and publish). Therefore, all publishing functions are performed by the server.

0
source

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


All Articles