Skip to content
This repository was archived by the owner on Oct 30, 2024. It is now read-only.

Commit 0ef397e

Browse files
committed
Replaced fgets with fread for binary messages
1 parent 068082e commit 0ef397e

1 file changed

Lines changed: 8 additions & 11 deletions

File tree

src/Connection.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -157,17 +157,13 @@ private function send($payload)
157157
*/
158158
private function receive($len = null)
159159
{
160+
160161
if ($len) {
161-
$line = fgets($this->streamSocket, $len + 1);
162+
$line = fread($this->streamSocket, $len);
162163
} else {
163164
$line = fgets($this->streamSocket);
164165
}
165-
166-
if ($line === false) {
167-
return $line;
168-
} else {
169-
return trim($line);
170-
}
166+
return $line;
171167
}
172168

173169
/**
@@ -337,14 +333,14 @@ private function handleMSG($line)
337333
{
338334
$parts = explode(' ', $line);
339335
$subject = null;
340-
$length = $parts[3];
336+
$length = trim($parts[3]);
341337
$sid = $parts[2];
342338

343339
if (count($parts) == 5) {
344-
$length = $parts[4];
340+
$length = trim($parts[4]);
345341
$subject = $parts[3];
346342
} elseif (count($parts) == 4) {
347-
$length = $parts[3];
343+
$length = trim($parts[3]);
348344
$subject = $parts[1];
349345
}
350346

@@ -373,7 +369,8 @@ public function wait($quantity = 0)
373369
$count = 0;
374370
while (!feof($this->streamSocket)) {
375371
$line = $this->receive();
376-
if ($line === false) {
372+
373+
if (sizeof($line) === 0) {
377374
return null;
378375
}
379376

0 commit comments

Comments
 (0)