I'm trying to understand more about long polling to "handle" a site in real time, I saw some videos and I'm thinking so far:
Let's say I have an old date that's in sql and I echo it.
How is long polling going to know if the old date isn't the same one it's going to fetch from time to time according to the setInterval… function?
Let's say I want to display a blog post where all the text is in mysql, but all of a sudden I publish a new post, and whoever is on the page right away will see the post right away ( ava ), so as a code Will long polling know the difference between the old post and the new one? Even to not give conflict or repeat the same date recorded in sql.
Remembering that I don't know anything about long polling, so I might be asking nonsense…
To use long-polling in this specific context, the ideal is the page that makes the long polling receive a parameter that corresponds to the last timestamp that the user has.
With that, the page makes a query to the database to check if there are more recent posts, and if there are, it returns the information.
On the client/browser side, when information is received from the long polled page, the html content is refreshed with the new information received, and the long polling page is called again with the timestamp of the information that was just completed. to receive.
Hope the text is not confusing 🙂
The difference is that instead of always making client-side ajax requests to see if there are new posts, you do one every x in x seconds or minutes, and then the request stays on the server side checking for new posts, and returns results if they appear.