3

We are planning to build a vast web application that provides real-time data update and display(sth like stockmarket). There is a need for efficient server-client bidirectional communication. After research html5 web-sockets seem a must. However there are several issues regarding compatibility and fallback as well as server support. We need a simple and stable solution in php preferable and apache integration. We made some tests with phpwebsockets and pywebsockets but they seem not so stable. What would you propose as a more stable - tested solution, sth like kaazing maybe but in php? Thank you in advance.

0

5 Answers 5

2

What you want to use is Socket.IO, which takes care of all the cross-browser issues and provides seamless fallbacks for the older browsers. Socket.IO was made to be used with Node.js, but can now be used with a number of different server-side languages.

However, I would NOT recommend using Web Sockets with PHP. Because PHP is not designed for long running bidirectional communication and will cause an entire Apache process/thread to lock up with each new connection.

I would highly recommend using a language like Node.js on the server-side, which can easily handle thousands of long running connections without any problems.

1

Did you try COMET?

Theres a lot of sample of COMET+PHP apps on web.

http://www.zeitoun.net/articles/comet_and_php/start

http://ajaxian.com/archives/comet-with-php

http://www.phpclasses.org/blog/post/58-Responsive-AJAX-applications-with-COMET.html

0

Nodejs for two reasons:

1: You can use the same language on both client and server, thus more code re-use.

2: The built in event loop makes javascript ideal for those "do a tiny bit of work and then sleep for 20 seconds" situations.

You have to love javascript to take it on the server though.

0

I would probably go with Node.js. While I love javascript, I'm not drunk the Node.js cool-aid. (Fair warning…)

But Node.js allows you to use Socket.io - and that is what you want to be using to make your real-time communication work seamlessly on "all" systems. Communication between PHP and Node.js can be handled through sockets, a database or some other insane stuff.

6
  • I also prefer nodejs, but he needs something easily compatible with php and apache. Perhaps run a node server too, add so much complexibility to his project Feb 15, 2012 at 13:01
  • Being a PHP dev myself I feel obligated to commicate: use the right tool for the job. PHP is NOT the right tool for the job. (Not saying that Node.js is either, but compared to PHP it's better suited because of Socket.io)
    – rodneyrehm
    Feb 15, 2012 at 13:03
  • Other than that, I'd probably suggest you it right and write something in Erlang. (yes, this is trolling and doesn't help at all. but for this, PHP by itself is like abusing a screw driver for a hammer)
    – rodneyrehm
    Feb 15, 2012 at 13:05
  • I saw more comet+PHP apps than nodejs+socket.io apps in production. I think Nodejs and socket.io is too 'young' (< version 1.0) to recommend as right tool for HIS job. Feb 15, 2012 at 13:09
  • I'm opting out of this discussion. it's beginning to feel like "Windows is the best OS because 1234234234 people are using it".
    – rodneyrehm
    Feb 15, 2012 at 13:51
0

WebSockets are not well supported, plus there is no stable php implementation.

Have you considered using long-polling/COMET? It will work across all browsers.

1
  • 1
    With the web-socket-js polyfill/fallback, WebSockets is usable on pretty much all browsers in the wild (as long as your server also supports the Hixie-76 protocol for iOS).
    – kanaka
    Feb 15, 2012 at 14:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.