PHP sockets worth it?

I'm just starting to use sockets to communicate with my Flex application, because I need a quick connection between the client and my server. I looked at PHP sockets, but since PHP was not running on the server this way (you can, but I feel this is disapproving) I'm not sure if PHP is the best way to communicate using Flex sockets.

My application requires the use of quick connection with the server, because it will include features such as private chat for other users, and remote control of the flex client from the server.

Should I use PHP sockets in my situation, or should I find an alternative language or even an alternative to sockets? My concern is that I will start using PHP sockets, but it will not be able to handle the load. Speed ​​can also be a problem when using PHP.

Edit:

Thanks for the answers, this is very much appreciated. As I can understand, PHP is stable when it comes to using sockets, but the language was intended only for use in a request / response environment, as Benson said.

Thanks to Cornel, a great alternative to my situation when using Flex with sockets was listed as BlazeDS , using Java instead of PHP.

+4
source share
4 answers

Defining your own protocol through simple sockets to implement messaging and remote communications will take a considerable amount of time - even for basic messaging functions. My suggestion is to use a server such as BlazeDS, if possible, you do not need to reinvent the wheel.

Yes, theoretically your application will run faster if the protocols are optimized for your specific use cases, but it will cost you a lot of development time.

+5
source

Actually it is my experience that PHP5 sockets are not bad. They are written in C and embedded in the PHP5 binary, so they will work quickly, unlike the implementation in PHP itself.

Check nanoweb and nanoserv:

http://nanoweb.si.kz/

http://nanoserv.si.kz/

The author did an impressive job of creating PHP sockets by building a high-performance pure-PHP web server with nanoweb and a complete daemon server infrastructure for PHP 5.1+ with nanoservice.

By looking at nanoservice-based documentation and codebases, you can trust PHP sockets more.

+4
source

PHP will pretty much match Linux sockets or the like, so I see no reason why this is a bad idea; since PHP is just a dynamic binding of the C. implementation

Looking at http://svn.php.net/viewvc/php/php-src/trunk/ext/sockets/sockets.c , it looks pretty reasonable.

Implementation, testing and testing. If he does not fall, he is fast enough, and the restrictions fit ... go for him.

+3
source

I also suggest node.js with sockets.io. Although this is best if you want to maintain an open asynchronous connection to the server. If you just make synchronous req / response calls, I will just use http + php.

Php is really intended to be used in an inconclusive response environment. It does not fit like a real application server. node.js is much better for this, but JavaScript is best for using json for serialization.

If performance is really important (real-time game), then the best binary protocol. Depends on what your application does. With node, this is json.decode 3k messages / sec on linux vm on my laptop. It is fast enough for everyone except real-time games.

+1
source

All Articles