I'm trying to create a bot script for a third party chat service using PHP. The client-server communication is based on socket.io, but works best with websockets - and, in fact, is quite easy to replicate without socket.io in browsers that support websockets. Unlike Javascript, however, PHP can't simply use new Websocket('ws://host')
and be connected. I've looked at PHP's raw(?) sockets such as fsockopen
and socket_create
, but I don't know what to use - socket_create
comes with the luxury of socket_select
, but I don't know how to use a socket of that type to target anything other than an IP address - in Javascript, the url the websocket connects to includes the session id. fsockopen
, on the other hand, can connect to a url this way, but I can't find any functions for waiting until the socket has bytes available to read. Every chat room requires a new socket (and session id), due to limitations of the service, so I need to be able to have multiple sockets all listening at the same time. What's the best direction to approach this from?
PHP中的外向websocket
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- dongwen7283 2012-05-09 02:58关注
Turns out the PHP manual isn't very explicit - you can connect to a url with
socket_connect
, it doesn't have to be an IP address. It'll be annoying to implement the entire websocket protocol by hand - but it is at least functional.本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 划分vlan后不通了
- ¥15 GDI处理通道视频时总是带有白色锯齿
- ¥20 用雷电模拟器安装百达屋apk一直闪退
- ¥15 算能科技20240506咨询(拒绝大模型回答)
- ¥15 自适应 AR 模型 参数估计Matlab程序
- ¥100 角动量包络面如何用MATLAB绘制
- ¥15 merge函数占用内存过大
- ¥15 使用EMD去噪处理RML2016数据集时候的原理
- ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
- ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数