[英]Connection to websocket server : OK from javascript, not OK from php
I am using socketio to run a websocket server.我正在使用 socketio 运行 websocket 服务器。
var fs = require('fs');
var options = {
key: fs.readFileSync('/etc/letsencrypt/live/my.domain.be/privkey.pem'),
cert: fs.readFileSync('/etc/letsencrypt/live/my.domain.be/fullchain.pem')
};
var app = require('https').createServer(options)
, io = require('socket.io').listen(app)
app.listen(6666);
Connecting to it from javascript (using socket.io client) works fine.从 javascript(使用 socket.io 客户端)连接到它工作正常。
var socket = io.connect('wss://my.domain.be:6666');
This works also :这也有效:
var socket = io.connect('https://my.domain.be:6666');
Now I want to connect using php.现在我想使用 php 连接。 I found a simple php client here : How can I send data/text from PHP using WebSocket to process?
我在这里找到了一个简单的 php 客户端: How can I send data/text from PHP using WebSocket to process?
But I see no incoming connection when using :但是我在使用时看不到传入连接:
$WebSocketClient = new WebsocketClient('wss://my.domain.be', 6666);
$WebSocketClient->sendData("MyUserNameFromPHP");
And I get the error :我得到错误:
Error: 22145040:Unable to find the socket transport "wss" - did you forget to enable it when you configured PHP?
错误:22145040:无法找到套接字传输“wss”——您是否在配置 PHP 时忘记启用它?
When using :使用时:
$WebSocketClient = new WebsocketClient('https://my.domain.be', 6666);
I get the error :我收到错误:
Error: 10905616:Unable to find the socket transport "https" - did you forget to enable it when you configured PHP?
错误:10905616:无法找到套接字传输“https” - 您是否在配置 PHP 时忘记启用它?
When using tls:// or ssl:// I get no output at all (and still no connection on my websocket server).使用 tls:// 或 ssl:// 时,我根本没有输出(并且在我的 websocket 服务器上仍然没有连接)。
So what am I missing to make a websocket connection from my php code ?那么从我的 php 代码建立 websocket 连接我错过了什么?
https://stackoverflow.com/a/61808878/3701985 please try my answer on another similar thread, I actually tried multiple solutions and now just want to provide answer which worked for me. https://stackoverflow.com/a/61808878/3701985请在另一个类似的线程上尝试我的回答,我实际上尝试了多种解决方案,现在只想提供对我有用的答案。 https://github.com/ratchetphp/Pawl
https://github.com/ratchetphp/Pawl
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.