Using WebSocket on Apache server
Asked Answered
A

4

39

With all the buzz around WebSockets, it's pretty hard to find a good walkthrough on how to use them with an Apache server on Google.

We're developing a plugin, in PHP (symfony2), which will run from time to time kind of a chat instance. And we find WebSockets more interesting, standard and quick than AJAX for this matter. The thing is, we don't have much sysadmin ressources in our group and we find hard to gather good informations on the following matters:

  • Can we run a WebSocket instance on a traditional Apache, dedicated server, and if yes, do you have useful links for us?
  • If we need to mod the server, what kind of tools would you recommend knowing that we are not too skilled in sysadmin so we can't afford to have a high maintenance b*** on this.

Thank you very much,

ps: we'll link back to your blog/site as we'll make a technical/informational post on our devblog about this part of our app.

Thank you again!

Acis answered 4/7, 2012 at 19:7 Comment(1)
You can try this too ApacheWSParaldehyde
S
14

One path is to use an independent installed web sockets server.

For PHP you can try: http://code.google.com/p/phpwebsocket/ or http://github.com/Devristo/phpws/

There are some other projects which you can try as well.

Basically, you need to upload, unpack and start running the process.

On the frontend, you'll have javascript connecting to the server on the specific port.

Most websocket servers have a demo which echoes back whatever it hears, so this is a good place to write some test code. You may even find a rudimentary chat implementation.

The tricky part is to monitor the web socket server and to make sure it runs smoothly and continuously.

Try to test on as many browsers/devices as possible as this will decide on which websocket server implementation you choose. There are old and new protocols you have to watch out for.

Saurel answered 4/7, 2012 at 19:19 Comment(3)
Thank you very much. Do you have any monitoring tool in mind by chance? Have a great time!Acis
We have our own light weight monitoring tools. For starters a simple cron script that checks when the process is not running and restarts it. You can build up from that or search for ready made process monitoring apps.Saurel
Ok, I'm sure our dev team is gonna be able to do something! Thanks again!Acis
L
17

As @zaf states you are more likely to find a standalone PHP solution - not something that runs within Apache. That said there is a apache WebSocket module.

However, the fundamental problem is that Apache wasn't built with maintaining many persistent connections in mind. It, along with PHP, is built on the idea that requests are made and responses are quickly sent back. This means that resources can very quickly be used up if you are holding requests open and you're going to need to look into horizontal scaling pretty quickly.

Personally I think you have two options:

  1. Use an alternative realtime web technology solution and communicate between your web application and realtime web infrastructure using queues or short-lived requests (web services).
  2. Off load the handling of persistent connections and scaling of the realtime web infrastructure to a realtime web hosted service. I work for Pusher and we fall into this category.

For both self-hosted and hosted options you can check out my realtime web tech guide.

Loth answered 5/7, 2012 at 15:22 Comment(2)
Very interesting stuff :) thank you very much! I love your guide, though it's not helping much to differenciate between solutions. We'll check documentation ;) thanks again!Acis
I do need to find the time to try out all the technologies and provide some guidance on the pros/cons of the different options. For now it's just a list to click-through - a starting point for your own investigations.Loth
S
14

One path is to use an independent installed web sockets server.

For PHP you can try: http://code.google.com/p/phpwebsocket/ or http://github.com/Devristo/phpws/

There are some other projects which you can try as well.

Basically, you need to upload, unpack and start running the process.

On the frontend, you'll have javascript connecting to the server on the specific port.

Most websocket servers have a demo which echoes back whatever it hears, so this is a good place to write some test code. You may even find a rudimentary chat implementation.

The tricky part is to monitor the web socket server and to make sure it runs smoothly and continuously.

Try to test on as many browsers/devices as possible as this will decide on which websocket server implementation you choose. There are old and new protocols you have to watch out for.

Saurel answered 4/7, 2012 at 19:19 Comment(3)
Thank you very much. Do you have any monitoring tool in mind by chance? Have a great time!Acis
We have our own light weight monitoring tools. For starters a simple cron script that checks when the process is not running and restarts it. You can build up from that or search for ready made process monitoring apps.Saurel
Ok, I'm sure our dev team is gonna be able to do something! Thanks again!Acis
C
6

I introduced another websocket server: PHP Ratchet (Github).

This is better and complete list of client & server side codes and browser support.

Please check this link.

Centrifugal answered 11/7, 2013 at 12:59 Comment(2)
Becuase it's FAST & EASY & React subset(reactphp.org). It has good documents & support.Centrifugal
can we have a look at any tests?Sirenasirenic
A
-2

Another Path is to use a dedicated websocket server.

Try Achex Websocket Server at www.achex.ca and checkout the tutorials.

OR

If you really want Apache, check out Apache Camel. (but you have to set it up and its a bit more complicated than achex server) http://camel.apache.org/websocket.html

Astoria answered 24/9, 2013 at 20:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.