Hi, I've been working on a new idea and would like it if I could get some feedback from some experienced web developers on how this would best work. What I am doing is creating a website where you can add an update, and this update is real-time updated on every other viewer that is currently on the page. I have done this with AJAX and PHP/MySQL and can run the ajax script on a js timer to query the database. I am also using jQuery to make the updates fade in nicely and get added to the top of the list. THe problems I am having is how do I make the update apply on everyones computer at once? I have had the issue where the update repeats multiple times, the update is only displayed on the first browser to recieve the update, the updates dont happen. I tryed using 2 different tables in a database and moving the data from 1 table to another when it has been updated. I have tryed using sessions to keep a count of the last viewed update so that when it updates it wont repeat old updates, I have tryed updating a value in the table to say it has been viewed. My most recent idea is having another table that registers the person viewing it and the update they have recieved, but this would mean I would have to register the users details or run from an IP address, but then IP's are unreliable due to people sharing 1 IP in offices of classrooms etc. I need some innovative ideas or solutions if anyone has any good ideas please could you share? Thanks
You could use a push server. Here is an example usage of comet with php - http://www.zeitoun.net/articles/comet_and_php/start
Would this mean that when a new post is entered, is will send the information to every browser with the website open? The problem i am having mainly is being able to only popup message that are new, not repeating those messages and making that consistent amongst every client. So that if one person adds an update, it will display on everyones browser as a new update, unless you arrive on the page after is has been submitted in which case it will already be present on the page.
A push server is most commonly a flash xml socket server. When a user enters your site the flash file establishes a connection with the socket server. You then have them "subscribe" to an item(page, db entry etc). Then when someone updates the item you connect to the socket server via the php backend and send the updates. The socket server then sends those updates to all users subscribed to that item.
Does anyone have any other ideas of how this could be achieved, mainly the problem of getting the update to apply to every bodies browser not just the first one. I am looking mainly for the database structure, and how I am to let each user know if there is an update available for them and once they have recieved it, not the recieve it as an update again
Any solution is going to be a bit of a hack as HTTP is designed as a pull technology not push however it can be achieved such as with http://www.howtocreate.co.uk/php/serverpushdemo.php The normal way of dealing with it is simply have ajax reload a section every X seconds. Therefore not everyone gets it at the same time but within X seconds of each other.
You should use a field like "updated" and another field like "timestamp". Check if "updated" has value of "1" and now - timestamp > 5 seconds, your script updates all fields