views:

332

answers:

2

How do I implement a PHP Socket Server, I am using PHP5.

Is there a ready made framework already available for me to use instead of going into the nitty gritties of the implementation details? Basically I want to serve Flash clients using this Socket Server and this would be running in an Apache Environment.

This is the first time I am treading into PHP territory so consider me a noob.

+1  A: 

Check out Zend_AMF (emphasis mine)

Zend_Amf provides support for Adobe's » Action Message Format (AMF), to allow communication between Adobe's » Flash Player and PHP. Specifically, it provides a gateway server implementation for handling requests sent from the Flash Player to the server and mapping these requests to object and class methods and arbitrary callbacks.

and AMFPHP as an alternative.

Also, check out PHP Socket's API and check out this IBM Article about Memory Management with PHP.

Edit This is not server push though. PHP is not well suited for long running processes. If you want a push implementation, have a look at Comet technologies.

Gordon
is it socket based? can the server push messages to clients, I want the clients to be always connected to the server.
Kevin Boyd
Like it says: *handling requests sent from the Flash Player to the server*. PHP is not a good choice for long running processes or push services atm. Search around for *Comet*.
Gordon
Since I am a noob in PHP I was just wondering why PHP is not a good choice for long running or push services?
Kevin Boyd
Because will start to leak memory when running. I have updated the anwer with an article about memory management.
Gordon
+1  A: 

Have a look at Aleksey Zapparov's PHP Socket server

http://www.phpclasses.org/browse/package/5758.html

Its very simple to hange your own code off it. But be warned that you should be careful about your memory management. If you're writing a very complex OO app, then you should definitely install the ciercular reference checking garbage collector. And, since it use socket_select() you don't want ti to be hanging around too long witing for your code to do something.

Alternatively (if you are running on anything other than a Microsoft platform) it may be simpler to hang the php process off [x]inetd and just use stdio for communications.

HTH

C.

symcbean
What's it about memory management, is the class heavy on memomry, What is HTH and C?
Kevin Boyd
CLients would generally be connected continuosly, is that too much to ask from PHP?
Kevin Boyd
HTH = Hope that helps, C = Me, if the answer doesn't make much sense then you should go read up on PHP memory management and garbage colelction, and make sure you monitor mem usage when testing your app.
symcbean
Are there any ready-made frameworks for comet in PHP?
Kevin Boyd