views:

813

answers:

3

Alright, I recently wrote a ajax push script which had php on the backend sleeping while waiting for someone to make an update. However, the sleeping processes took up a lot of cpu. Any ideas on how I can prevent this? I am guessing I will have to either find a program which can do the sleeping with threads or write my own in python or c++ which I am not very familiar with. I am using ajax push for a browser based game so people can play it in real time but I think if I get too many sleeping processes on the backend it would overload the server.

A: 

If I understand correctly, you want some kind of long-polling stuff -- you should search for the term "comet".

For instance, here are a couple of posts that might interest you :


Still, one might say that PHP, because of its non-threaded model, I suppose, is not the best language/technology for that kind of stuff... And maybe you'll end up looking to another technology for that part of your site...

For instance, you can take a look at :

Pascal MARTIN
A: 

After much research last night, I found this as the answer for the server side. Then write a php script for the client side. Then have ajax call the client which calls the server. Only problem is some of the extensions have to be manually installed.

http://php-mag.net/itr/online%5Fartikel/psecom,id,484,nodeid,114.html

David