I have been fiddling with a chat program for some time now.
Polling with AJAX has been successful, but it sends a request to the server every second, which seems too expensive to me, not to mention every 1000ms is slow these days.
Long-polling has been UNSUCCESSFUL. I found that I CAN do a long-polling request on my server (Apache) but that if I have a long-polling request running, the rest of the webpage is rendered 'dead'. I can't click in a text box or type or whathaveyou.
I now know that this is because Apache uses multiple threads for a long-polling request and thus consumes a lot of resource, unlike other server types.
My questions:
1.How can I create the same "instant message functionality" without long-polling (or how can I functionally and successfully do long-polling on Apache?). I just need
When (someone sends a message and thus a file on server changes) {send data to all users;},
should be easy enough right?
I notice that facebook does long-polling for the client (in Firebug), BUT Gmail chat apparently does not and yet has the same functionality?!
2.How does gmail chat do it?
I have read the wiki about Comet and this article and watched an informative video, where the speaker says this can be done with PHP/JS, and have a good understand of the IDEA, I just want the CODE..
I have found a long-polling PHP and Apache workable solution. And it is a charm.
http://www.zeitoun.net/articles/comet_and_php/start
All I had to do was set_time_limit(0);
in backend.php and all is as it should be.