Parcourir la source

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.
Daniele Alessandri il y a 10 ans
Parent
commit
8373663486
1 fichiers modifiés avec 1 ajouts et 1 suppressions
  1. 1 1
      lib/Predis/Connection/PhpiredisStreamConnection.php

+ 1 - 1
lib/Predis/Connection/PhpiredisStreamConnection.php

@@ -151,7 +151,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');