dongxiangchan0743 2011-06-08 02:09
浏览 70

没有使用间隔的AJAX Shoutbox,可以这样做吗?

Ok, I am seeking a way for a shoutbox to trigger ONLY when a message is inputted into it by anyone.

Basically, we have control over what happens when someone submits a shout, but I don't want to use a Javascript interval (setTimeout() or setInterval()) functions to call this every x amount of seconds. Because every x amount of seconds it is hitting the database trying to determine if a shout has been made or not.

There MUST be a better method to do this that doesn't hit the database every x seconds in order to update the Shoutbox for everyone to see the shout.

This is where I need help, because our shoutbox is using too many resources on the server and causing the server to overload at times.

I have thought about a file instead... For example, when a shout has been posted to the shoutbox, a filename on the server changes to something, this filename than gets checked (instead of the database), and if the filename is different, than it should load up the shout. Perhaps, it can even place the shout within the file, instead of the database, and ONLY stick it into the database after another shout has been added to the shoutbox. Therefore, the last shout will always remain in the file, in text format.

Would this be a better approach for handling server overloads? But even still I would need to call an interval to determine if the file name changed. So this is still calling an interval, but do you think it would be better on the server this way? If so, what name should I use? Should I use the php time() function for this to name the file?

Are there any other ideas that someone could recommend to handle this. Preferably a way without using any intervals to update the shoutbox?

Please help, thanks guys :)

  • 写回答

2条回答 默认 最新

  • doudou130216 2011-06-08 02:16
    关注

    What you are getting close to with your descriptions of a possible solution is more like a server push than a page get.

    I know you can achieve this sort of behavior using node.js with a Transfer-encoding: chunked. Check out the video at http://www.nodejs.org/ for a better example

    评论

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算