Portal Home > Knowledgebase > Articles Database > ajax push script


ajax push script




Posted by Syphic, 08-11-2009, 12:17 AM
I have written a really simple push script using php and jquery ajax. However, the way I had to write the php was a while script which loops continually until an update it sent and then it turns false, send out the message, and starts again. Problem is the php while script is eating up the server. I put in a usleep of 100,000 which is .1 sec but still eating it up and the more people who use this the more of these scripts run. So, any ideas? 1. Find a way to make the while less cpu intensive. 2. Setup a socket server and have the ajax connect to it. 3. ?????

Posted by cselzer, 08-11-2009, 01:33 AM
Use flash, controlled by javascript as a bridge to connect to a socket, and write the socket server in a language that actually supports threading, php supports forking, which isn't effective imo. Example: http://matthaynes.net/blog/2008/07/1...socket-bridge/ I recommend using python for the server. Lots of free resources out there for it.

Posted by Syphic, 08-11-2009, 01:51 AM
I was trying to just use jquery (ajax) on the front end and php on the back end. I got it working with out any problems; just the php script while doing the "while" loop is maxing out the cpu and if several are initiated it just keeps it max but does not really overload it per say.

Posted by Xeentech, 08-11-2009, 05:09 AM
I'm working on the same sort of thing currently. We're using XMPP over Ajax/HTTP.. so It's a little more complicated that what you're doing, bt essentially the same thing. We're using ProxyPass in Apache to pass requests for /bosh onto a custom socket server that uses select() to multiplex sockets. ProxyPass is really only for our development environment. We're expecting to move to something more scalable, like HAProxy, once we deploy.



Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read
Shoutbox? (Views: 492)