swoole是支持wss的方法

swoole是支持wss的方法

1 先让swoole支持ssl

首先编译的时候 加上–enable-openssl

然后打命令查看/usr/local/php/bin/php –ri swoole

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

看到openssl => enabled 就代表可以了

然后swoole写如下代码就行

$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,
));

ps:前端必须要用wss才能连接 ws会链接失败

原创文章如转载,请注明本文链接: http://newmiracle.cn/?p=3160

发表评论

电子邮件地址不会被公开。 必填项已用*标注