quipo/kafka-php — pull request #7 by shyamalprasad (2014-03-10 23:38:54+00:00)
Title: Allow arbitrary number of fread calls when receiving large data packets.

Prior code did a maxiumum of 40 read retries 5ms apart when reading a
large data packet. A message that requires more than 40 reads from
the socket will never complete!

This commit keeps reading from the socket as long as data is arriving
from the server within the configured default socket timeout. Error
handling could be improved, but this is the simplest patch I could come
up with to support the $verifyExactLength parameter as defined.

BTW I have been using this patch to read 1 MB+ message sizes
across a US transcontinental link for several days now. It is definitely
an improvement (the prior code simply fails). I would probably write the
code a little differently if $verifyExactLength=true was the only option,
but this patch works fine the way things are currently defined.

The only problem that *might* still remain is if the select call fails with
EAGAIN the loop terminates as if there was a timeout. I say "might"
because I don't quite know how different PHP implementations treat
an interrupted system call, and I've not seen it fail yet in practice (Debian
stable and Mac OS X). I, or some one else, can patch that when and
if appropriate!