Reputation: 637
I'm using a chat in a system that got approximately 100 active users. The chat is built with javascript that runs an ajax question every fourth second to a php script that fetches data from the database. The server gets extremely slow when there are about 100 users online on the server.
Are there a better way to create a chat than using javascript intervals containing ajax questions?
Kind regards / H
Upvotes: 1
Views: 598
Reputation: 51241
Using a timeout for the ajax communication is probably the worst solution you can do.
I suggest you either use Websockets or AJAX Longpolling. There is a jquery plugin which works with websockets (with graceful degradation). Perhaps you even might want to try out socket.io which combines this all into a neat framework (node.js serverside).
This answer gives you some information on how to possibly achieve this with having PHP on the serverside.
Upvotes: 1
Reputation: 237
This is the problem of using unidirectional request : the client has to ask the server permanently to see if there is some new information. As a result, it add some charge to the server. See Polling on wiki.
A solution is to use a bidirectional request system. This would allow the server to send data to the client by itself, and not just waiting an incoming query to respond. This would remove the polling principle and some charge off the server.
I see three solution for this :
Maybe the third solution would be the simplest to setup as it does not include new technology in your current architecture.
Upvotes: 1