skip to Main Content

I’m working on Angular app using Php Phalcon framework for backend. So i have some server data shown in tables. It can be changed by client async, but i can’t know when data is actually changed. Also i need update it as far as another client change it.

One of my ideas was to update data on regular basis, but i find this a bit clunky and think it is not really the way this should work.

Other way is to create some event on server so client could know he should get new data version.

How do i implement this? Maybe there are some instruments i could use for that?

2

Answers


  1. The first thing you are describing is called polling. This regularly requests the new data from the server to kind of always be up to date.

    This is not real-time but usually easier to implement because you don’t have to change the server.
    You can do this with rxjs by using the timer(...) or delay(...) and repeat() operators. See the docs for an example

    The second way is real-time but requires you to do some changes to your server.

    One way would be to establish a WebSocket connection between the client and the server. This can then be used to inform the client about new data directly.
    RxJS supports webSockets.
    This would be my preferred solution to real-time updates.

    Another option would be to use Server-Sent Event which is basically a one-way event from server -> client. But this is not supported in Internet Explorer or Edge. This is also currently not directly supported by RxJS but you can create your own wrapper as discussed here.

    Login or Signup to reply.
  2. Polling is not a good idea in most cases. You spend too many resources, plus, you are overloading the server with requests.

    The most straight forward solution, if you have access to the backend, is to create a Server-Sent Event (SSE) connection.

    You can find many resources online. I hope this helps.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search