Skip to content

Commit d94bf39

Browse files
committed
修正options配置无效问题.
1 parent b64724a commit d94bf39

File tree

4 files changed

+19
-20
lines changed

4 files changed

+19
-20
lines changed

src/concerns/InteractsWithServer.php

-8
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,6 @@ trait InteractsWithServer
2828
*/
2929
public function run(): void
3030
{
31-
$this->getServer()->set([
32-
'task_enable_coroutine' => true,
33-
'send_yield' => true,
34-
'reload_async' => true,
35-
'enable_coroutine' => true,
36-
'max_request' => 0,
37-
'task_max_request' => 0,
38-
]);
3931
$this->initialize();
4032
$this->triggerEvent('init');
4133

src/config/swoole.php

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
'package_max_length' => 20 * 1024 * 1024,
2323
'buffer_output_size' => 10 * 1024 * 1024,
2424
'socket_buffer_size' => 128 * 1024 * 1024,
25+
'task_enable_coroutine' => true,
26+
'send_yield' => true,
27+
'reload_async' => true,
28+
'enable_coroutine' => true,
29+
'task_max_request' => 1000,
30+
'max_request' => 1000,
2531
],
2632
],
2733
'websocket' => [

src/websocket/Pusher.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ protected function getWebsocketConnections(): array
169169
*/
170170
protected function shouldPushToDescriptor(int $fd): bool
171171
{
172-
if (!$this->server->exist($fd)) {
172+
if (!$this->server->isEstablished($fd)) {
173173
return false;
174174
}
175175

src/websocket/socketio/Handler.php

+12-11
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,26 @@ public function __construct(Server $server, Config $config)
2626
/**
2727
* "onOpen" listener.
2828
*
29-
* @param int $fd
29+
* @param int $fd
3030
* @param Request $request
3131
*/
3232
public function onOpen($fd, Request $request)
3333
{
3434
if (!$request->param('sid')) {
35-
$payload = json_encode(
35+
$payload = json_encode(
3636
[
37-
'sid' => base64_encode(uniqid()),
38-
'upgrades' => [],
37+
'sid' => base64_encode(uniqid()),
38+
'upgrades' => [],
3939
'pingInterval' => $this->config->get('swoole.websocket.ping_interval'),
40-
'pingTimeout' => $this->config->get('swoole.websocket.ping_timeout'),
40+
'pingTimeout' => $this->config->get('swoole.websocket.ping_timeout'),
4141
]
4242
);
43-
$initPayload = Packet::OPEN . $payload;
43+
$initPayload = Packet::OPEN . $payload;
4444
$connectPayload = Packet::MESSAGE . Packet::CONNECT;
45-
46-
$this->server->push($fd, $initPayload);
47-
$this->server->push($fd, $connectPayload);
45+
if ($this->server->isEstablished($fd)) {
46+
$this->server->push($fd, $initPayload);
47+
$this->server->push($fd, $connectPayload);
48+
}
4849
}
4950
}
5051

@@ -81,7 +82,7 @@ public function onClose($fd, $reactorId)
8182
protected function checkHeartbeat($fd, $packet)
8283
{
8384
$packetLength = strlen($packet);
84-
$payload = '';
85+
$payload = '';
8586

8687
if ($isPing = Packet::isSocketType($packet, 'ping')) {
8788
$payload .= Packet::PONG;
@@ -91,7 +92,7 @@ protected function checkHeartbeat($fd, $packet)
9192
$payload .= substr($packet, 1, $packetLength - 1);
9293
}
9394

94-
if ($isPing) {
95+
if ($isPing && $this->server->isEstablished($fd)) {
9596
$this->server->push($fd, $payload);
9697
}
9798
}

0 commit comments

Comments
 (0)