Skip to content

Commit

Permalink
Merge pull request #2 from DeepDiver1975/bugfix/1
Browse files Browse the repository at this point in the history
Detect connection abort
  • Loading branch information
hhxsv5 authored Jun 22, 2018
2 parents 49ece5f + 26f3645 commit f0d1eac
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/SSE.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public function start(Update $update, $eventType = null)
$changedData = $update->getUpdatedData();
if ($changedData !== false) {
$event = [
'id' => uniqid(),
'id' => uniqid('', true),
'type' => $eventType,
'data' => (string)$changedData,
'retry' => 2000,//reconnect after 2s
Expand All @@ -23,6 +23,10 @@ public function start(Update $update, $eventType = null)
echo new Event($event);
ob_flush();
flush();
// if the connection has been closed by the client we better exit the loop
if (connection_aborted()) {
return;
}
sleep($update->getCheckInterval());
}
}
Expand Down

0 comments on commit f0d1eac

Please sign in to comment.