Javascript 对 Web 套接字的原生 PHP 支持是否可用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12203443/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 07:24:06  来源:igfitidea点击:

Is native PHP support for Web Sockets available?

phpjavascriptwebsocket

提问by

Looking for Hello World Type Example of Web Sockets Implementation:

寻找 Web Sockets 实现的 Hello World 类型示例:

Here is Socket Createreference from php.net but this looks more low level than Web Sockets.

这是来自 php.net 的Socket Create参考,但这看起来比 Web Sockets 更底层。

I want to use this Web Sockets as shown here on caniuse.comwhich is now implemented in all new major browsers.

我想使用这里在caniuse.com上显示的 Web 套接字,它现在已在所有新的主要浏览器中实现。

A Google search turned up this Nets.TutsPlus sitein which I can use the JavaScript example code...but I need to know how to implement the server-side in PHP not Java, Ruby, or Node.js as in the example.

谷歌搜索出现了这个Nets.TutsPlus 站点,我可以在其中使用 JavaScript 示例代码……但我需要知道如何在 PHP 中实现服务器端,而不是示例中的 Java、Ruby 或 Node.js。

Is PHP Socket Create relevant? Does PHP natively support Web Sockets? I guess just a point in the right direction for PHP implementation would help.

PHP Socket Create 相关吗?PHP 本身是否支持 Web 套接字?我想在 PHP 实现的正确方向上有一点会有所帮助。

Actually the tutorial has a broken link to phpwebsockets...is this the library one should use?

实际上,本教程有一个指向 phpwebsockets 的断开链接……这是应该使用的库吗?

Websockets.orghas a test application, but no mention of PHP.

Websockets.org有一个测试应用程序,但没有提到 PHP。

采纳答案by leggetter

There isn't native support in terms of there being a standard PHP WebSocket object natively available.

就存在本机可用的标准 PHP WebSocket 对象而言,没有本机支持。

You'll need to use a library.

你需要使用一个库。

The next thing to consider is how the WebSocket server runs. Normally PHP runs in Apache, Nginx (via FastCGI) or on Microsoft IIS (via Fast CGI). With Apache and IIS this may be a problem as it's not really built with persistent connections such as WebSockets in mind. I'm not sure about Nginx. This is why most PHP WebSocket libraries will be built as standalone libraries to be run as their own processes.

接下来要考虑的是 WebSocket 服务器的运行方式。通常 PHP 在 Apache、Nginx(通过 FastCGI)或 Microsoft IIS(通过 Fast CGI)上运行。对于 Apache 和 IIS,这可能是一个问题,因为它并没有真正使用持久连接(如 WebSockets)构建。我不确定 Nginx。这就是为什么大多数 PHP WebSocket 库将构建为独立库以作为它们自己的进程运行。

See:

看:

Note: IE10 is now released in Windows 8

注意:IE10 现已在 Windows 8 中发布

Also see: Ajax push system

另见:Ajax推送系统