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.
some links about reverse http: reverse http 1 making-real-time-web-real-time reverse http 2 rest-requires-asynchronous-notification
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 :
- Is there some way to PUSH data from web server to browser?
- Online tutorials for implementing comets (server push)
- Using comet with PHP?
- Problem of choosing comet server
- Comet & PHP: How to use Comet with a PHP Chat System ?
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 :
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