1

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..

khaverim
  • 2,828
  • 5
  • 30
  • 43
  • Yep, there is also COMET technologies, (like APE (AJAX Push Engine)) – Doug Molineux Aug 13 '12 at 17:16
  • "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." ... That has nothing to do with the ability to interact with the page in the browser. – SLaks Aug 13 '12 at 17:16
  • Further to the above take a look at http://socket.io/ for a cross-browser solution – WayneC Aug 13 '12 at 17:16
  • @SLaks, Yes, it does, clearly, because when I have a long-polling request pending even using usleep() in the 'waiting' PHP script, the page becomes 'unclickable' and 'untypable' – khaverim Aug 13 '12 at 17:18
  • @khanahk: Unless you're using evil synchronous AJAX (don't), that won't happen. – SLaks Aug 13 '12 at 17:21
  • This could be what you are looking for: http://stackoverflow.com/questions/603201/using-comet-with-php – Paul Aug 13 '12 at 17:27

1 Answers1

0

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.

Makoto
  • 96,408
  • 24
  • 164
  • 210
khaverim
  • 2,828
  • 5
  • 30
  • 43