I've coded an AJAX chatroom, where the client sends a request to check for new messages every .4 seconds. Unfortunately every once in a while the request doesn't go through, which doesn't matter so much for checking messages, but logging on/off the chatroom uses the same method, and the list of users online doesn't update properly if the request doesn't go through. How do I make the client wait until the server is free to send requests?
If you're having problems, don't use AJAX for the critical requests. Refresh for logging in and out. Also, how did you come up with .4 seconds? That seems a little much... I would think that you could check once a second, and then you're only putting 40% as much stress on your server. If you do that, you'll be able to process more requests.
0.4 seconds was a result of testing with a couple people, general consesus was that it should be that responsive. It massacred the server, so I did some tweaking and it runs along pretty well with 5-6 people. Logging in and out is actually just loading and unloading the site, with an ajax request on sign out. I brought the refresh back up to 1 second but the problem persists, even with just one user online. Is there no way to check whether the server is busy, and resubmit the request until it goes through?
ummm......... 'kay. It's running on my design pc's testing server so I am fully prepared for it to be royally screwed. It does not work in IE for some reason I have yet to determine.
I'd need to see some of the PHP to help more. The only suggestion I would have so far is to use some more "best practice" AJAX... Don't use innerHTML, but rather DOM methods. And don't return HTML from a PHP script (which you look to be doing for your user list), but return XML, and let javascript parse it.