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

こ雲淡風輕ζ 提交于 2021-02-19 08:03:08

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/16107842/how-to-update-page-content-while-multiple-users-view-it-at-the-same-time-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!