@@ -18,9 +18,9 @@ class Connection
1818
1919 /**
2020 * Chunk size in bytes to use when reading with fread.
21- * @var int
21+ * @var integer
2222 */
23- private $ chunkSize = 8192 ;
23+ private $ chunkSize = 1500 ;
2424
2525 /**
2626 * Return the number of pings.
@@ -167,12 +167,13 @@ private function receive($len = null)
167167 $ receivedBytes = 0 ;
168168 while ($ receivedBytes < $ len ) {
169169 $ bytesLeft = $ len - $ receivedBytes ;
170- if ( $ bytesLeft < $ this ->chunkSize ) {
170+ if ($ bytesLeft < $ this ->chunkSize ) {
171171 $ chunkSize = $ bytesLeft ;
172172 }
173173
174- $ line .= fread ($ this ->streamSocket , $ chunkSize );
175- $ receivedBytes += $ chunkSize ;
174+ $ readChunk = fread ($ this ->streamSocket , $ chunkSize );
175+ $ receivedBytes += strlen ($ readChunk );
176+ $ line .= $ readChunk ;
176177 }
177178 } else {
178179 $ line = fgets ($ this ->streamSocket );
@@ -183,8 +184,8 @@ private function receive($len = null)
183184 /**
184185 * Returns an stream socket to the desired server.
185186 *
186- * @param string $address Server url string.
187- * @param float $timeout Number of seconds until the connect() system call should timeout.
187+ * @param string $address Server url string.
188+ * @param float $timeout Number of seconds until the connect() system call should timeout.
188189 *
189190 * @return resource
190191 * @throws \Exception Exception raised if connection fails.
@@ -196,7 +197,7 @@ private function getStream($address, $timeout = null)
196197 }
197198 $ errno = null ;
198199 $ errstr = null ;
199-
200+
200201 $ fp = stream_socket_client ($ address , $ errno , $ errstr , $ timeout , STREAM_CLIENT_CONNECT );
201202 $ timeout = number_format ($ timeout , 3 );
202203 $ seconds = floor ($ timeout );
@@ -367,7 +368,7 @@ private function handlePING()
367368 * @param string $line Message command from Nats.
368369 *
369370 * @return void
370- * @throws Exception
371+ * @throws Exception If subscription not found.
371372 * @codeCoverageIgnore
372373 */
373374 private function handleMSG ($ line )
@@ -470,9 +471,11 @@ public function reconnect()
470471 }
471472
472473 /**
473- * @param integer $chunkSize Set byte chunk len to read when reading from wire
474+ * @param integer $chunkSize Set byte chunk len to read when reading from wire.
475+ * @return void
474476 */
475- public function setChunkSize ($ chunkSize ){
477+ public function setChunkSize ($ chunkSize )
478+ {
476479 $ this ->chunkSize = $ chunkSize ;
477480 }
478481
0 commit comments