Skip to content

Commit 70f49d0

Browse files
committed
调整websocket与http默认设置
1 parent a271ce4 commit 70f49d0

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

example.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111
'port' => '9000',
1212
'type' => SWOOLE_SOCK_TCP,
1313
'setting' => [
14-
'open_http_protocol' => false,
15-
'open_websocket_protocol' => true,
16-
'task_worker_num' => 1,
14+
'daemonize' => false,
15+
'task_worker_num' => 1,
1716
],
1817
'handler' => \swoole_websocket_and_tcp_and_udp_test\webscoket::class,
1918
],
@@ -22,10 +21,7 @@
2221
'host' => '0.0.0.0',
2322
'port' => '9001',
2423
'type' => SWOOLE_SOCK_TCP,
25-
'setting' => [
26-
'open_http_protocol' => true,
27-
'daemonize' => false,
28-
],
24+
'setting' => [],
2925
'handler' => \swoole_websocket_and_tcp_and_udp_test\http::class,
3026
],
3127
'tcp' => [

src/Server.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,23 @@ public function __construct($config)
3535
if (isset($this->config['websocket'])) {
3636
$this->enableWebsocket = true;
3737
$this->primaryConfig = $this->config['websocket'];
38+
$this->primaryConfig['setting']['open_websocket_protocol'] = true;
39+
if(!isset($this->primaryConfig['setting']['open_http_protocol'])) {
40+
$this->primaryConfig['setting']['open_http_protocol'] = true;
41+
}
42+
if(!isset($this->primaryConfig['setting']['daemonize'])) {
43+
$this->primaryConfig['setting']['daemonize'] = false;
44+
}
45+
3846
$serverClass = \swoole_websocket_server::class;
3947
} else {
4048
if (isset($this->config['http'])) {
4149
$this->primaryConfig = $this->config['http'];
50+
$this->primaryConfig['setting']['open_http_protocol'] = true;
51+
if(!isset($this->primaryConfig['setting']['daemonize'])) {
52+
$this->primaryConfig['setting']['daemonize'] = false;
53+
}
54+
4255
$serverClass = \swoole_http_server::class;
4356
}
4457
}

0 commit comments

Comments
 (0)