title: PHP Websocket client + ssl
body: <p>There is a PHP Websocket client: <a href="https://github.com/symbiose/php-websocket-client" rel="nofollow">https://github.com/symbiose/php-websocket-client</a> repository. And it works fine for not-secured connection.</p>
  
  <p>What I need is to connect to a websocket server from php code through secure connection. To implement this task I took the code above and modified it a bit. The connect() method of WebSocketClient now looks like this in my code:</p>
  
  <pre><code>public function connect()
  {
      $root = $this;
      if ($this-&gt;getPort() == 443) {
        $context = stream_context_create();
        stream_context_set_option($context, 'ssl', 'allow_self_signed', true);
        stream_context_set_option($context, 'ssl', 'verify_peer', false);
        $client = stream_socket_client("tls://{$this-&gt;getHost()}:{$this-&gt;getPort()}", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context);
      } else {
        $client = stream_socket_client("tcp://{$this-&gt;getHost()}:{$this-&gt;getPort()}", $errno, $errstr);
      }
      if (!$client) {
          throw new RuntimeException('Cannot connect to socket ([#'.$errno.'] '.$errstr.')');
      }
      $this-&gt;setSocket(new Connection($client, $this-&gt;getLoop()));
      $this-&gt;getSocket()-&gt;on('data', function ($data) use ($root) {
          $data = $root-&gt;parseIncomingRaw($data);
          $root-&gt;parseData($data);
      });
      $this-&gt;getSocket()-&gt;write($this-&gt;createHeader());
      return $this;
  }
  </code></pre>
  
  <p>As a result I almost managed to connect to a server. Websocket server saw my connection, replied that everything is ok and wrote it to the log.</p>
  
  <p>But unfortunately, the library doesn't understand, that it has successfully connected to the server.</p>
  
  <p>This "if":</p>
  
  <pre><code>    if (base64_encode(pack('H*', sha1($this-&gt;key . '258EAFA5-E914-47DA-95CA-C5AB0DC85B11'))) === $response['Sec-Websocket-Accept']) {
          $this-&gt;connected = true;
      } 
  </code></pre>
  
  <p>never gets executed. And so I can't establish the connection.</p>
  
  <p>I can also confirm, that if we use 80 port - everything works like a charm.</p>
  
  <p>So if you have any ideas on why this can happen, i"d really really appreciate them. Cause I've already ran out of ideas.</p>
  
  <p>Best regards,
  Kostya </p>