Sync Effect using jQuery based Ajax/PHP?
Get the solution ↓↓↓I'm building a groceries application that allows for syncing with other members in your family who are part of a 'family' group, and when one of them update the grocery list on their devices, it will update automatically on other devices. I can do pretty much everything, but the automatically bit.
I've got .load working with setInterval, but it only functions (stable) when the interval is set to a few minutes, because making the call once every few seconds is a bit excessive on the server :\
I believe the way to do this is with long polling, which I still have no idea how to do, but could anyone suggest how I could do this efficiently? In a way that might not lag like crazy on mobile too? Because I do intend to push this over to mobile.
Or if it means less load on the server, would anyone know how to do it like Twitter does '1 new Tweet' when new content gets detected?
Any help greatly appreciated! :)
Cheers, Karan
Answer
Solution:
If you're frequent polling is too excessive on the server then you need to revise the logic on the server. Rather than hit the database during every single request you should have something where the server caches a status in a session variable or something similar. Then when a user makes a change, invalidate the cache, so that after that one of those poll requests from the Javascript actually incurs the full hit to the server.
Another thing I would say is be careful on the long running response paradigm. It's a handful and practically everything I've seen in the wild has used frequent polling instead. Take a peak at this old thread.
If you are still interested in the long running response have a look at Comet.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: invalid argument supplied for foreach() laravel
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.