Pārlūkot izejas kodu

More reliable network writes in Predis\Protocols\TextProtocol.

Daniele Alessandri 14 gadi atpakaļ
vecāks
revīzija
8a145bc6c9
1 mainītis faili ar 11 papildinājumiem un 1 dzēšanām
  1. 11 1
      lib/Predis.php

+ 11 - 1
lib/Predis.php

@@ -1581,7 +1581,17 @@ class TextProtocol implements IRedisProtocol {
             $buffer .= "\${$arglen}\r\n{$argument}\r\n";
         }
 
-        fwrite($connection->getResource(), $buffer);
+        $socket = $connection->getResource();
+        while (($length = strlen($buffer)) > 0) {
+            $written = fwrite($socket, $buffer);
+            if ($length === $written) {
+                return;
+            }
+            if ($written === false || $written === 0) {
+                $this->onCommunicationException('Error while writing bytes to the server');
+            }
+            $value = substr($buffer, $written);
+        }
     }
 
     public function read(IConnectionSingle $connection) {