@@ -16,6 +16,12 @@ class Connection
16
16
*/
17
17
private $ pings = 0 ;
18
18
19
+ /**
20
+ * Chunk size in bytes to use when reading with fread.
21
+ * @var int
22
+ */
23
+ private $ chunkSize = 8192 ;
24
+
19
25
/**
20
26
* Return the number of pings.
21
27
*
@@ -176,7 +182,21 @@ private function receive($len = null)
176
182
{
177
183
178
184
if ($ len ) {
179
- $ line = fread ($ this ->streamSocket , $ len );
185
+ $ chunkSize = $ this ->chunkSize ;
186
+ $ line = null ;
187
+ $ receivedBytes = 0 ;
188
+ while ($ receivedBytes < $ len ) {
189
+ $ bytesLeft = $ len - $ receivedBytes ;
190
+ if ( $ bytesLeft < 1500 ) {
191
+ $ chunkSize = $ bytesLeft ;
192
+ }
193
+
194
+ $ line .= fread ($ this ->streamSocket , $ chunkSize );
195
+ $ receivedBytes += $ chunkSize ;
196
+ }
197
+ if (strlen ($ line ) > 2 ) {
198
+ $ line = substr ($ line , 0 , -2 );
199
+ }
180
200
} else {
181
201
$ line = fgets ($ this ->streamSocket );
182
202
}
@@ -467,6 +487,13 @@ public function reconnect()
467
487
$ this ->connect ($ this ->timeout );
468
488
}
469
489
490
+ /**
491
+ * @param integer $chunkSize Set byte chunk len to read when reading from wire
492
+ */
493
+ public function setChunkSize ($ chunkSize ){
494
+ $ this ->chunkSize = $ chunkSize ;
495
+ }
496
+
470
497
/**
471
498
* Close will close the connection to the server.
472
499
*
0 commit comments