Page 1 of 1

AJAX instant Messenger

Posted: Wed Mar 04, 2009 11:48 am
by Omego2K
I am looking for a technique to implement an AJAX instant messenger. I understand that polling makes it possible, but if you look at say gmail and facebook instant messengers they seem to be, well, instant. I have tested it with two computers and I see no noticeable delay. I'm guessing that is considered a comet implementation, but I can't seem to see how it can be done. At least with php. I have tried it with ASP.NET and was able to do it with threading, however you can't thread with php. So am I missing something obvious? How is this being done? Especially since facebook uses php.

Re: AJAX instant Messenger

Posted: Wed Mar 04, 2009 4:11 pm
by VladSun
You could keep the HTTP connection opened and wait something to "happen" (by using sleep() in a loop). If nothing "happens" then close the connection just before the timeout.

Re: AJAX instant Messenger

Posted: Tue Mar 10, 2009 6:22 am
by Omego2K
wouldn't spinning like that be a huge a resource hog? sleep() pauses the thread itself I'm guessing?

Re: AJAX instant Messenger

Posted: Tue Mar 10, 2009 6:30 am
by VladSun
Omego2K wrote:wouldn't spinning like that be a huge a resource hog? sleep() pauses the thread itself I'm guessing?
While it's CPU friendly, it's not so Apache friendly (there is a limit of the maximum number of Apache spawned child processes) :)

So, if you are going to serve many and many clients don't use it, use AJAX instead.
But if you are going to use it for just a few clients (i.e. Intranet WWW application) it's better to use this approach.

Re: AJAX instant Messenger

Posted: Tue Mar 10, 2009 12:33 pm
by Omego2K
so what's the best server to use to accomplish this, on windows specifically? IIS?