phpajaxlive-update

How to update page content while multiple users view it at the same time in PHP?


My page is visited by multiple users at the same time.

User 1: visits the page and changes the name of title

User 2: user 2 was already on that page but sees the old title, the title automatically has to be updated to new title.

I know i can simply use AJAX to call every 5 minutes, but im trying to see if there is any other way possible that fires an event to all instances of the page opened by different users that if one of them is updated all other pages get automatically updated with latest data without the wait of 5 minute ajax call. Ajax seems inefficient since it will do many ajax calls and also what happens if user 1 updates title while user 2 updates title as well before user 2's page has been updated with 5 minute ajax call.

Not asking for a code, just need an advise whether I should keep using AJAX calls every 5 minutes and be happy with it or there is a better solution.


Solution

  • Try investigating web sockets for real time, two way communication between server and browser.

    http://socketo.me/

    I'm in the early stages of working with it myself but it seems like a solution that would fit your requirements.

    Also, maybe look at push notifications

    e.g. http://www.pubnub.com/blog/php-push-api-walkthrough