PHP中的WebSocket客户端? [英] WebSocket client in PHP?

查看:440
本文介绍了PHP中的WebSocket客户端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否存在用于从PHP连接到WebSocket服务器的库或客户端?如果没有,为什么?

Is there a library or client for connecting to a WebSocket server from PHP? If not, is there a reason why?

(( phpwebsocket 似乎只有Javascript客户端代码.)

(phpwebsocket only seem to have Javascript client code.)

推荐答案

以上都不是一个好的答案.其中有几个是关于服务器的,而问题是关于客户端的. Rodislav的代码对我不起作用,因为它无法与Heroku上的WebSockets服务器通信.但是,该库运行良好:

None of the above is a good answer. Several of them are about a server, whereas the question is about a client. The code from Rodislav didn't work for me, as it didn't talk to my WebSockets server on Heroku. However, this library worked very well:

https://github.com/Devristo/phpws

更新:虽然这段代码在一切正常的情况下仍然有效,但似乎根本没有错误返回或异常,因此,当出现错误时,它是不可用的(例如,服务器未运行,地址是错误的) ,端口被阻塞等).因此,尽管进行试验很有趣,但是它在生产代码中不可用.

UPDATE: While this code worked when all was well, there seems to be no error returns or exceptions at all, and as a result it's unusable when there's an error (e.g., the server isn't running, the address is wrong, the port is blocked, etc.). So, while it was fun to experiment with, it's not usable in production code.

这篇关于PHP中的WebSocket客户端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆