doufu5401 2011-11-11 08:19
浏览 27

使用基于jQuery的Ajax / PHP同步效果?

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

  • 写回答

1条回答 默认 最新

  • doujian7132 2012-01-31 23:07
    关注

    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.

    Comet VS Ajax polling

    If you are still interested in the long running response have a look at Comet.

    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程