Sfoglia il codice sorgente

Merge pull request #439 from ares333/optimize-ws-encode

optimize Ws protocol encode performance
walkor 6 anni fa
parent
commit
e54d5f95ad
1 ha cambiato i file con 2 aggiunte e 3 eliminazioni
  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) {