php 的swoole 和websocket 连接wss

1. 下载证书

$serv = new swoole_server('0.0.0.0', 9501, SWOOLE_PROCESS, SWOOLE_SOCK_TCP | SWOOLE_SSL);
$serv->set(array(
'ssl_cert_file' => __DIR__.'/config/ssl.crt',
'ssl_key_file' => __DIR__.'/config/ssl.key',
   'worker_num' => 2,
   'task_worker_num' => 2
));

2.swoole 编译时需要--enable-openssl的支持

  重新编译swoole, 加上此编译

  php 的swoole 和websocket 连接wss

3.websocket 请求

var wsServer = 'wss://mini.vic.net:9501'; # 域名和购买的证书要一直
var websocket = new WebSocket(wsServer);
websocket.onopen = function (evt) {
console.log("Connected to WebSocket server.");
}; websocket.onclose = function (evt) {
console.log("Disconnected");
}; websocket.onmessage = function (evt) {
console.log('Retrieved data from server: ' + evt.data);
}; websocket.onerror = function (evt, e) {
console.log('Error occured: ' + evt.data);
};
上一篇:fiddler 新发现


下一篇:php 安装 Redis 扩展