Ver código fonte

optimize Ws protocol encode performance

Ares 6 anos atrás
pai
commit
981eea39b2
1 arquivos alterados com 2 adições e 3 exclusões
  1. 2 3
      Protocols/Ws.php

+ 2 - 3
Protocols/Ws.php

@@ -254,9 +254,8 @@ class Ws
 
         $frame = $head . $mask_key;
         // append payload to frame:
-        for ($i = 0; $i < $length; $i++) {
-            $frame .= $payload[$i] ^ $mask_key[$i % 4];
-        }
+        $mask_key = str_repeat($mask_key, floor($length / 4)) . substr($mask_key, 0, $length % 4);
+        $frame .= $payload ^ $mask_key;
         if ($connection->handshakeStep === 1) {
             // If buffer has already full then discard the current package.
             if (strlen($connection->tmpWebsocketData) > $connection->maxSendBufferSize) {