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.
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(?).
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!