1.首先找到网站根目录下/vendor/topthink/think-swoole/src/Server.php中75行,即:public function __construct(),添加ssl服务类型
public function __construct()
{
// 实例化 Swoole 服务
switch ($this->serverType) {
case 'socket':
$this->swoole = new Websocket($this->host, $this->port, $this->mode, $this->sockType);
break;
case 'http':
$this->swoole = new HttpServer($this->host, $this->port, $this->mode, $this->sockType);
break;
// 增加ssl类型服务
case 'ssl':
$this->swoole = new Websocket($this->host, $this->port, $this->mode, $this->sockType);
break;
default:
$this->swoole = new SwooleServer($this->host, $this->port, $this->mode, $this->sockType);
}
//...
}
2.在配置文件swoole_server.php修改配置
// +----------------------------------------------------------------------
// | Swoole设置 php think swoole:server 命令行下有效
// +----------------------------------------------------------------------
return [
// 扩展自身配置
'host' => '0.0.0.0', // 监听地址
'port' => 9508, // 监听端口
'type' => 'socket', // 服务类型 支持 socket http server
'mode' => '', // 运行模式 默认为SWOOLE_PROCESS
// 'sock_type' => '',// 默认为SWOOLE_SOCK_TCP
'swoole_class' => '', // 自定义服务类名称
'sock_type' => SWOOLE_SOCK_TCP | SWOOLE_SSL, // sock type 默认为SWOOLE_SOCK_TCP
'serverType' => 'ssl',
'ssl_key_file' => '/www/server/panel/vhost/ssl/XXXXX/privkey.pem',
'ssl_cert_file' => '/www/server/panel/vhost/ssl/XXXXX/fullchain.pem',
// 可以支持swoole的所有配置参数
'daemonize' => false, //守护进程
'pid_file' => Env::get('runtime_path') . 'swoole_server.pid',
'log_file' => Env::get('runtime_path') . 'swoole_server.log',
'worker_num' => 3, //进程数
//心跳检测:每60秒遍历所有连接,强制关闭10分钟内没有向服务器发送任何数据的连接
'heartbeat_check_interval' => 10,
'heartbeat_idle_time' => 60,
'buffer_output_size' => 4*1024*1024, // 发送输出缓存区内存
'socket_buffer_size' => 4*1024*1024, // 配置客户端连接的缓存区长度
//...
];