mirror of
https://github.com/nextcloud/all-in-one.git
synced 2026-05-28 14:30:13 +00:00
Read streamed output line by line, not via buffer
This way the code doesn't wait for a buffer to be filled, and we don't need to implement logic ourselves that is provided by a present library already. Signed-off-by: Pablo Zmdl <pablo@nextcloud.com>
This commit is contained in:
@@ -11,6 +11,7 @@ use AIO\Data\ConfigurationManager;
|
||||
use AIO\Data\DataConst;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use GuzzleHttp\Psr7\Utils;
|
||||
use http\Env\Response;
|
||||
|
||||
readonly class DockerActionManager {
|
||||
@@ -842,22 +843,12 @@ readonly class DockerActionManager {
|
||||
|
||||
if ($outputCallback !== null) {
|
||||
$body = $startResponse->getBody();
|
||||
$buffer = '';
|
||||
while (!$body->eof()) {
|
||||
$chunk = $body->read(1024);
|
||||
$buffer .= $chunk;
|
||||
while (($pos = strpos($buffer, "\n")) !== false) {
|
||||
$line = substr($buffer, 0, $pos);
|
||||
$buffer = substr($buffer, $pos + 1);
|
||||
$line = rtrim($line, "\r");
|
||||
if ($line !== '') {
|
||||
$outputCallback($line);
|
||||
}
|
||||
$line = rtrim(Utils::readLine($pullBody), "\r");;
|
||||
if ($line !== '') {
|
||||
$outputCallback($line);
|
||||
}
|
||||
}
|
||||
if (trim($buffer) !== '') {
|
||||
$outputCallback(trim($buffer));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user