Using WebSocket on Apache server

旧街凉风 提交于 2019-11-27 11:40:12
zaf

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.

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.

ShahRokh

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!