I am not very educated on this topic of programming so I am seeking any advice/knowledge. I am coding a web app in PHP, and this particular task requires updating the display after the server has new information available. So, one seemingly-bad solution is to have a repeating AJAX request that spams the server on an interval, and updates when it gets new data. This puts a lot of stress on the server, so it seems unviable to me.

We attempted to use Ratchet (http://socketo.me/) but could not really figure it out. Is this overcomplicating this, or is there another way we can solve this problem while still keeping server load as "practically" minimal as possible. There are websites like Facebook/most social media that dynamically show new data as it's available -- I assume they also use something that minimizes requests to the server? Or is this assumption incorrect?

1 Answer 1


Big question: how quickly does the display on the client need to update when there is new data on the server? Within 1 second? 10 seconds? 1 minute?

Another big question: how many clients do you expect might use your system at the same time?

If the client needs to be updated within a fraction of a second, then yes, polling the server (using repeated AJAX requests) is probably a bad idea. If 10 seconds, 30 seconds, or even a couple minutes response time is OK, then polling will probably be fine.

Assuming your data is in a relational DB, make sure there are indexes in place which can be used to retrieve the "new" data quickly. If you are not using a relational DB, understand the performance implications of how your particular DB accesses data, and do whatever is necessary so the "new" data can be accessed quickly, without much computation OR I/O.

(For reference: I recently built a system with clients which poll the server every 3 minutes -- I have an updated_at timestamp on all the records which the client is interested in, and an index on the timestamp. When the server sends data to the client, it also sends a timestamp which tells it "this data is valid as of such-and-such a time". Next time the client polls for more data, it sends the timestamp it received so the server can retrieve the records which have been updated in the meantime.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.