swoole是支持wss的方法
swoole是支持wss的方法
1 先让swoole支持ssl
首先编译的时候 加上--enable-openssl
然后打命令查看/usr/local/php/bin/php --ri swoole
<pre>
swoole
swoole support => enabled
Version => 1.9.23
Author => tianfeng.han[email: mikan.tenny@gmail.com]
epoll => enabled
eventfd => enabled
timerfd => enabled
signalfd => enabled
cpu affinity => enabled
spinlock => enabled
rwlock => enabled
async http/websocket client => enabled
openssl => enabled
Linux Native AIO => enabled
pcre => enabled
zlib => enabled
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
Directive => Local Value => Master Value
swoole.aio_thread_num => 2 => 2
swoole.display_errors => On => On
swoole.use_namespace => Off => Off
swoole.fast_serialize => Off => Off
swoole.unixsock_buffer_size => 8388608 => 8388608
</pre>
看到openssl => enabled 就代表可以了
然后swoole写如下代码就行
<pre>
$ws = new swoole_websocket_server("0.0.0.0", 9908, SWOOLE_PROCESS, SWOOLE_SOCK_TCP | SWOOLE_SSL);
$ws->set(array(
'worker_num' => 1,
'max_conn' => 65535,
'ssl_cert_file'=>'cert/1965653_wxserver.knowway.cn.pem',
'ssl_key_file' =>'/cert/1965653_wxserver.knowway.cn.key',
// 'daemonize' => true,
'backlog' => 128,
// 'task_worker_num' => 1,
));
</pre>
ps:前端必须要用wss才能连接 ws会链接失败
如果遇到什么不懂的地方直接关注公众号留言(本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须在文章页面给出原文连接,否则保留追究法律责任的权利。)
作者:newmiracle
出处:https://www.cnblogs.com/newmiracle/