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会链接失败

 

posted @ 2019-11-12 15:59  newmiracle宇宙  阅读(1064)  评论(0编辑  收藏  举报