websocket服务,ssl时报错

SSL

执行命令

php --ri swoole

结果如下

swoole

swoole support => enabled
Version => 2.0.12
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
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 => On => On
swoole.fast_serialize => Off => Off
swoole.unixsock_buffer_size => 8388608 => 8388608

启动一个websocket服务,代码是从源码粘贴过来的案例,将证书改为了我在阿里云申请的域名ssl证书,如下

 $ssl_dir = realpath('/etc/nginx');
        $serv = new \swoole_websocket_server("0.0.0.0", 9502, SWOOLE_BASE, SWOOLE_SOCK_TCP | SWOOLE_SSL);
//$serv = new \swoole_websocket_server("0.0.0.0", 9502, SWOOLE_PROCESS, SWOOLE_SOCK_TCP | SWOOLE_SSL);
        $serv->set([
            'ssl_cert_file' => $ssl_dir . '/cert/21567/0567.pem',
            'ssl_key_file' => $ssl_dir . '/cert/21567/0567.key',
            'worker_num' => 1,
        ]);
        $port = $serv->listen('127.0.0.1', 9501, SWOOLE_SOCK_TCP);
        $port->on('receive', function($serv, $fd, $reactor_id, $data){
            var_dump($fd, $reactor_id, $data);
            $serv->send($fd, "Swoole: $data");
        });
        $serv->on('connect', function ($_server, $fd) {
            echo "client {$fd} connect\n";
        });
        $serv->on('open', function (\swoole_websocket_server $_server, swoole_http_request $request) {
            echo "server#{$_server->worker_pid}: handshake success with fd#{$request->fd}\n";
//    var_dump($request);
        });
...

启动服务,总是报错如下:

Use of undefined constant SWOOLE_SSL - assumed 'SWOOLE_SSL'

请求指点,这是哪里出错了?感激不尽。

2018-01-17 14:05
0
0

clz

赞同来自:

问题解决了,swoole用pecl安装的,默认没有开启openssl,看上面的

php --ri swoole
~~~返回的信息值,
重新安装swoole,如下,开启openssl

git clone https://github.com/swoole/swoole-src.git cd swoole-src phpize ./configure --enable-openssl make && make install

再次执行命令查看信息如下,跟原来的比发现多了一个openssl的支持

swoole

swoole support => enabled Version => 2.0.13 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 => On => On swoole.fast_serialize => Off => Off swoole.unixsock_buffer_size => 8388608 => 8388608

~~~ 问题解决了。

2018-01-17 15:01

要回复问题请先登录注册