Skip to content

Commit 56f3b6b

Browse files
authored
Reading whole lines from stream (#576)
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.
1 parent 15d0142 commit 56f3b6b

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

src/Connection/Protocols/ImapProtocol.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,10 @@ protected function enableStartTls(): void {
135135
* @throws RuntimeException
136136
*/
137137
public function nextLine(Response $response): string {
138-
$line = "";
139-
while (($next_char = fread($this->stream, 1)) !== false && !in_array($next_char, ["", "\n"])) {
140-
$line .= $next_char;
141-
}
142-
if ($line === "" && ($next_char === false || $next_char === "")) {
138+
$line = fgets($this->stream);
139+
if ($line === false || $line === '') {
143140
throw new RuntimeException('empty response');
144141
}
145-
$line .= "\n";
146142
$response->addResponse($line);
147143
if ($this->debug) echo "<< " . $line;
148144
return $line;

0 commit comments

Comments
 (0)