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 :)
You might want to look into HTML5's WebSockets, but for non-compatible browsers I think you're stuck with continuously polling the server on an interval.
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
精彩评论