I don’t know how to search about this so I’m kinda lost (the two topics I saw here were closed).
I have a news website and I want to warn the user when a new data is inserted on the database. I want to do that like here on StackOverflow where we are warned without reloading the page or like in facebook where you are warned about new messages/notifications without reloading.
Which is the best way to do that? Is it some kind of listener with a timeout that is constantly checking the database? It doesn’t sounds efficient…
Thanks in advance.
You need javascript ajax and json and callback function to check constantly. It can be done by push services but PHP is bad with that and you need websockest, etc. facebook uses timeout calls. not sure for the stackoverflow
then in PHP, for example you have a flag in database with which you check if data is new to teh databse. Mind the formatting and to proper sql escape
;
After that you can create another ajax call that marks messages as read once user clicks on them. or opens a dialog listing or wahtever