Skip to content

Commit 6f1d467

Browse files
authored
Merge pull request #1 from appwrite-labs/fix-realtime-speed
Fix: realtime chunking speed
2 parents b3f4ca2 + 3f8b5f3 commit 6f1d467

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/KubernetesCluster.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -267,15 +267,24 @@ protected function watchLogsPath(string $path, Closure $callback, array $query =
267267

268268
$data = null;
269269

270-
while (($data = fgets($sock)) == true) {
271-
$call = call_user_func($callback, $data);
272-
273-
if (! is_null($call)) {
274-
fclose($sock);
275-
276-
unset($data);
277-
278-
return $call;
270+
$chunk = '';
271+
while (($data = fgets($sock, 64)) == true) {
272+
$chunk .= $data;
273+
274+
$separator = \strrpos($chunk, "\n");
275+
if ($separator !== false) {
276+
$extra = \substr($chunk, $separator + \strlen("\n"));
277+
$chunk = \substr($chunk, 0, $separator) . "\n";
278+
279+
$call = call_user_func($callback, $chunk);
280+
if (!is_null($call)) {
281+
fclose($sock);
282+
unset($data);
283+
unset($chunk);
284+
return $call;
285+
}
286+
287+
$chunk = $extra;
279288
}
280289
}
281290
}

0 commit comments

Comments
 (0)