使用Apache的mod_proxy_wstunnel连接到PHP,而不使用第三方api

时间:2022-08-30 21:45:53

I am new to WebSocket world and even after a week, I still could not find how to use it with PHP without using any 3rd Party Library. Or not sure if it is even possible.

我是WebSocket世界的新手,即使在一个星期之后,我仍然无法找到如何使用PHP而不使用任何第三方库。或者不确定这是否可能。

I have 3 questions,

我有3个问题,

1) Do we must need to use some 3rd Party APIs or Libraries like Ratchet, PHP-Push-WebSocket or PHP WebSocket to enable PHP to communicate over WebSocket protocol?

1)是否需要使用第三方api或库,如Ratchet、PHP- push -WebSocket或PHP WebSocket,使PHP能够通过WebSocket协议进行通信?

2) If your answer to above question is yes then what is the advantage/purpose of using Apache's mod_proxy_wstunnel?

2)如果您对上述问题的回答是肯定的,那么使用Apache的mod_proxy_wstunnel的优点/目的是什么?

3) If I use any PHP WebSocket 3rd Party Library, then do I still need to enable and use Apache's mod_proxy_wstunnel? If No, then again what is the purpose of Apache's mod_proxy_wstunnel?

3)如果我使用任何PHP WebSocket第三方库,那么我还需要启用和使用Apache的mod_proxy_wnel吗?如果没有,那么Apache的mod_proxy_wstunnel的目的是什么?

I went through this Using go-websocket behind Apache mod_proxy_wstunnel. In this question, the OP has indicated some go-websocket but unfortunately the link is giving 404 Error and hence I cannot understand if the user has used any 3rd Party API.

我在Apache mod_proxy_wstunnel后面使用了go-websocket。在这个问题中,OP指出了一些go-websocket,但不幸的是链接给出了404错误,因此我无法理解用户是否使用了任何第三方API。

Any help would be highly appreciated. Thanks in advance.

如有任何帮助,我们将不胜感激。提前谢谢。

1 个解决方案

#1


5  

PHP is not created for WS. Of course you can do this, but it is full of while (true) and fsock_open [*]. And you have to have access to the shell to run the WS-server with php-cgi. (usually)

PHP不是为WS创建的。当然您可以这样做,但是它充满了while (true)和fsock_open[*]。您必须访问shell以使用php-cgi运行WS-server。(通常)

Choose a language that supports threads / asynchronous communication. Now on the top is Node.js. In addition, better use dedicated libraries to support older browsers, etc. If you are thinking about alternatives to ajax then you can use socket.io. If you want to create one-to-all communication (eg chat, broadcast messaging), go one step further and use one of the Bayeux implementations, for example: Faye.

选择一种支持线程/异步通信的语言。上面是Node.js。此外,最好使用专用库来支持旧的浏览器等等。如果您想创建一对一的通信(如聊天、广播消息),请进一步使用Bayeux实现之一,例如:Faye。

The mod_proxy_wstunnel extension adds an extra layer to the WS server. Depending on the configuration, it can support DDoS, queue, load-balancing, local port swapping, and https support. But better use this for nginx.

mod_proxy_wstunnel扩展为WS服务器添加了一个额外的层。根据配置,它可以支持DDoS、队列、负载平衡、本地端口交换和https支持。但是最好用这个来表示nginx。

So, for test you don't need mod_proxy_wstunnel, and on production, you should add an extra layer of security, eg NGINX ws tunelling.

因此,对于测试,您不需要mod_proxy_wstunnel,并且在生产时,您应该添加额外的安全层,例如NGINX ws隧道。

[*] Sorry, I made some mistakes. PHP has native support for WebSockets. That content is going to set you negatively to WS in PHP.

对不起,我犯了一些错误。PHP对WebSockets有本地支持。这个内容会让你对PHP中的WS产生负面影响。

Websockets are events, and PHP is poorly managed with it.

Websockets是事件,PHP在这方面的管理也很糟糕。

#1


5  

PHP is not created for WS. Of course you can do this, but it is full of while (true) and fsock_open [*]. And you have to have access to the shell to run the WS-server with php-cgi. (usually)

PHP不是为WS创建的。当然您可以这样做,但是它充满了while (true)和fsock_open[*]。您必须访问shell以使用php-cgi运行WS-server。(通常)

Choose a language that supports threads / asynchronous communication. Now on the top is Node.js. In addition, better use dedicated libraries to support older browsers, etc. If you are thinking about alternatives to ajax then you can use socket.io. If you want to create one-to-all communication (eg chat, broadcast messaging), go one step further and use one of the Bayeux implementations, for example: Faye.

选择一种支持线程/异步通信的语言。上面是Node.js。此外,最好使用专用库来支持旧的浏览器等等。如果您想创建一对一的通信(如聊天、广播消息),请进一步使用Bayeux实现之一,例如:Faye。

The mod_proxy_wstunnel extension adds an extra layer to the WS server. Depending on the configuration, it can support DDoS, queue, load-balancing, local port swapping, and https support. But better use this for nginx.

mod_proxy_wstunnel扩展为WS服务器添加了一个额外的层。根据配置,它可以支持DDoS、队列、负载平衡、本地端口交换和https支持。但是最好用这个来表示nginx。

So, for test you don't need mod_proxy_wstunnel, and on production, you should add an extra layer of security, eg NGINX ws tunelling.

因此,对于测试,您不需要mod_proxy_wstunnel,并且在生产时,您应该添加额外的安全层,例如NGINX ws隧道。

[*] Sorry, I made some mistakes. PHP has native support for WebSockets. That content is going to set you negatively to WS in PHP.

对不起,我犯了一些错误。PHP对WebSockets有本地支持。这个内容会让你对PHP中的WS产生负面影响。

Websockets are events, and PHP is poorly managed with it.

Websockets是事件,PHP在这方面的管理也很糟糕。