tags:

views:

36

answers:

2

I'm building a small chat application to add to an existing framework. There will only be 20-50 users MAX at any one time. I was wondering if I could get away with updating a cache file containing (semi) live chat data for whichever users happen to be chatting just by performing timed queries and regular AJAX refreshes for new data as opposed to learning how to open and maintain a socket connection.

I'm sure there are existing chat plug-ins out there. But I just had a hell of a time installing one and I could see building the whole damn thing taking just as much time as plugging one in.

Am I off to a bad start?

Thanks in advance -J

(p.s. this is a semi closed network behind a php login so security isn't a great concern)

A: 

First of all, I would suggest reading up on JavaScript Long Polling to retrieve your data instantaneously.

As far as collecting and distributing your data, I would recommend you use a database that supports LISTEN and NOTIFY. (For example, Postgres provides you with pg_get_notify() in PHP)

With long-polling and a notification-enabled database like Postgres, you could easily build a real-time, scalable chat application.

Other resources and links:

Kenaniah
A: 

I second that long polling is a good approach. However, understanding it, and doing it correctly, is far more difficult than just polling in intervals. With 20-50 users, scalability shouldn't be an issue. For a good long polling design, you should look at how you can avoid to suspend a server thread for the lifetime of an http request.

It could be wise to start out with a simple polling approach, advancing to long polling later on.

k_b