简体   繁体   中英

Updating Webpage in Real Time

I'm in the process of making a browser based multiplayer turnbased strategy game similiar to Risk.

Right now, the easiest way to do things seems to be to just make it like a regular webpage. Each time a player refreshes, the webpage queries the database for the information it needs.

This is acceptable, but I'd MUCH rather have the page update in real time so the players don't have to constantly refresh the page.

I could just have the web page query the database every X seconds, but I've heard this isn't efficient.

What would be the best way to do this?

Try Socket.io library or Juggernaut2 . You will need a Redis adapter to use Juggernaut2, take a look at PhpRedis .

A better approach instead of refreshing the entire page, would be to use a jscript that will poll the server and receive a JSON result and will update the page accordingly.

This will result in a much faster and smoother user experience (as the page is not refreshed), and better performance\\work-load for your servers.

For an even beter approach, you should look at a COMET PHP implementation which is an pub-sub like approach

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM