Fast Private Message

Hi guys.

I need to do "fast message" on site.

What do I mean? - When User1 send to User2 message, User2 instantly receive notice about new message.

How I see implementation of this task: when User1 send message to User2, in table ‘user’(id, username,…, count_new_message), counter’s (count_new_message) value will changed. By dint of ajax request User2 take a notice about message. But I think that this decision not good, because too many request to server will overload it.

If anybody solve task like this, please help.

P.S.: sorry for my english

Well at some point you have to query your server. And Ajax is a rather lightweight and efficient method. For your enquiry, you may want to check Server-Sent Events wiki:

Well, it depends on what is "fast" in your terms… .

I fully agree - polling from client side using AJAX, every few seconds/minutes interval is hardly scale-able.

Maybe do it on the next page refresh plus email notification? (is that fast enough for you? it comes down to the same issue of what is "fast enough" for you…).

Unless you have a really good reason for really live notification I recommend you stick with update of recipient in the form of a counter somewhere on the recipient’s browser that will update on the next page refresh. After all, you’re not designing SaaS email service but rather just messaging between users on the site. I guess that what’s good for LinkedIn, Yii framework and many other similar sites can be good for you(?).


bennouna, thanks. I will try.

To Boaz:

>> Well, it depends on what is "fast" in your terms… .

few weeks :)) joke:)

But seriously, I think than email notification good idea.

Tonight I was read some topics, and they are recommended use XMPP protocol.

Unless you are building an email client or other website where this speed is essential I think you’re requirement here is an exaggeration. Most community websites, social network websites etc will do very well with email notification + a little counter that will be promoted on next page refresh (a widget in Yii terms, embedded into your layout, for example).

But, YMMV and ultimately its your call. Good luck with it anyway!