views:

334

answers:

2

I need to create a chat similar to facebook chat.

I am thinking to use ajax polling ( to send request every 2-3 seconds ).

Is this a good approach ? Or I need to use other server side languages like erlang and server-comet ?

+2  A: 

Or I need to use other server side languages

No - that's not really relevant - the biggest problem is that HTTP does not support push notifications - so the language you use on the web server is pretty much irrelevant.

server-comet ?

Comet is programming technique - not a language - specifically designed to address the absence of push in HTTP. Conventionally, a browser sends a request, the webserver creates a response then sends it back to the client. With Comet, the webserver waits until either:

1) there is some update to include in the response

2) a timer expires

Before sending the response. A consequence of this is that it results in a high number if inactive connections to the webserver - which can cause performance issues.

An alternative approach is to use HTTP to delver a client program to run in the browser which the connects to the chat server using a different protocol. Its possible to do this with ActiveX, Java or flash - all of which have major drawbacks - not least portability.

There are several pre-written solutions out there using PHP and javascript - hint - if the docs don't mention Naggle then they've probably not thought about scalability/performance.

C.

symcbean
A: 

It depends how many users you have I guess. It will work when you don't have many users(That's how they did it in the past). But in my opinion the chat is not real-time because you can have delays up too x seconds(polling interval).

With a lot of concurrent users the polling model will not scale. Then you should really look into non-blocking long-polling(at least). I think if at all possible you should look into the non-blocking long-polling technique because that's how the big sites do real-time application. But your server should allow you to install other programming languages because PHP is not right for this technique.

Alfred