From 30a47d9398678197d7d62406ead1dc73ba449cfc Mon Sep 17 00:00:00 2001 From: wurst-hans <56444979+wurst-hans@users.noreply.github.com> Date: Wed, 7 May 2025 14:00:30 +0200 Subject: [PATCH] Reading whole lines from stream Replaced char-by-char retrieval from stream via fread() with fgets() to get full line from stream until EOF or newline. This speeds up data transfer by factor 10. --- src/Connection/Protocols/ImapProtocol.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Connection/Protocols/ImapProtocol.php b/src/Connection/Protocols/ImapProtocol.php index ed1dac6e..6871d57f 100644 --- a/src/Connection/Protocols/ImapProtocol.php +++ b/src/Connection/Protocols/ImapProtocol.php @@ -135,14 +135,10 @@ protected function enableStartTls(): void { * @throws RuntimeException */ public function nextLine(Response $response): string { - $line = ""; - while (($next_char = fread($this->stream, 1)) !== false && !in_array($next_char, ["", "\n"])) { - $line .= $next_char; - } - if ($line === "" && ($next_char === false || $next_char === "")) { + $line = fgets($this->stream); + if ($line === false || $line === '') { throw new RuntimeException('empty response'); } - $line .= "\n"; $response->addResponse($line); if ($this->debug) echo "<< " . $line; return $line;