Skip to content
This repository was archived by the owner on Mar 24, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
check fd connection before push
  • Loading branch information
albertcht committed Apr 15, 2018
commit 3a312b7ba7d6049725fc6dbc09d5a261abb1617f
14 changes: 9 additions & 5 deletions src/Server/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,15 @@ public function onTask(HttpServer $server, $taskId, $fromId, $data)
{
$this->container['events']->fire('swoole.task', func_get_args());

// push websocket message
if ($this->isWebsocket
&& array_key_exists('action', $data)
&& $data['action'] === Websocket::PUSH_ACTION) {
$this->pushMessage($server, $data['data'] ?? []);
try {
// push websocket message
if ($this->isWebsocket
&& array_key_exists('action', $data)
&& $data['action'] === Websocket::PUSH_ACTION) {
$this->pushMessage($server, $data['data'] ?? []);
}
} catch (Exception $e) {
$this->logServerError($e);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/Websocket/CanWebsocket.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function pushMessage(Server $server, array $data)
$message = $this->formatter->output($event, $data['message']);

// attach sender if not broadcast
if (! $broadcast && ! in_array($sender, $fds)) {
if (! $broadcast && $sender && ! in_array($sender, $fds)) {
$fds[] = $sender;
}

Expand All @@ -132,8 +132,9 @@ public function pushMessage(Server $server, array $data)
}
}

// push message to designated fds
foreach ($fds as $fd) {
if ($broadcast && $sender === (integer) $fd) {
if (($broadcast && $sender === (integer) $fd) || ! $server->exist($fd)) {
continue;
}
$server->push($fd, $message, $opcode);
Expand Down