From 4db00173f37cf8befcf197ee3f94997f4abf365e Mon Sep 17 00:00:00 2001 From: Daniele Alessandri Date: Mon, 23 Jun 2014 14:14:22 +0200 Subject: [PATCH] Use stream_socket_recvfrom() in PhpiredisStreamConnection. Similarly to the socket-ext based connection using phpiredis, in our stream based PhpiredisStreamConnection class we should read data from the stream using stream_socket_recvfrom() instead of fread() because the latter could block until a timeout is reached when the read buffer contains less data then the specified length. IMPORTANT: stream_socket_recvfrom() bypasses stream wrappers which means that TLS/SSL, as requested by PR #158, won't ever work with this connection class as the function returns the original encrypted bytes. This commit fixes issue #180. --- lib/Predis/Connection/PhpiredisStreamConnection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Predis/Connection/PhpiredisStreamConnection.php b/lib/Predis/Connection/PhpiredisStreamConnection.php index 22f45dba..1bb43421 100644 --- a/lib/Predis/Connection/PhpiredisStreamConnection.php +++ b/lib/Predis/Connection/PhpiredisStreamConnection.php @@ -141,7 +141,7 @@ class PhpiredisStreamConnection extends StreamConnection $reader = $this->reader; while (PHPIREDIS_READER_STATE_INCOMPLETE === $state = phpiredis_reader_get_state($reader)) { - $buffer = fread($socket, 4096); + $buffer = stream_socket_recvfrom($socket, 4096); if ($buffer === false || $buffer === '') { $this->onConnectionError('Error while reading bytes from the server.');