Pergunta

Coming from Python/Java/PHP, I'm now building a website. On it I want a list of items to be updated in near-realtime: if items (server side) get added to or deleted from the list, this should be updated on the webpage. I made a simple API call which I now poll every second to update the list using jQuery. Because I need some more lists to be kept updated on the same page I'm afraid this will turn into more than 10 server calls per second from every single open browser, even if nothing gets updated.

This seems not like the logical way to do it, but I don't really know how else to do it. I looked at Meteor, but since the webpage I'm building is part of a bigger system I'm rather restricted in my choices of technology (basic LAMP setup).

Could anybody enlighten me with a tip from the world of real-time websites on how to efficiently keep a list updated?

Foi útil?

Solução

You can use WebSocket(https://code.google.com/p/phpwebsocket/ ) technology.

but php is not the best language for implement it

Outras dicas

A way to work this is using state variables for the different types of data you want to have updated (or not).

In order to avoid re-querying the full tables even if the data set in them has not changed in relation to what a particular client has displayed at any given time, you could maintain a state counter variable for the data type on the server (for example in a dedicated small table) and on the client in a javascript variable.

Whenever an update is done on the data tables on the server, you update the state counter there.

Your AJAX polling calls would then query this state counter, compare it to the corresponding javascript variable, and only do a data-update call if it has changed, updating the local javascript variable to what the server has.

In order to avoid having to poll for each datatype separately, you might want to use an JS object with a member for each datatype.

Note: yes this is all very theoretical, but, hey, so is the question ;)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top