title: WebSockets (JS,Apache,PHP)
body: <p>I'm simply trying to get a WebSocket handshake down using javascript, apache, php.</p>
  
  <p>For clarity before we begin:</p>
  
  <ul>
  <li><em>Server version: Apache/2.4.7 (Ubuntu)</em></li>
  <li><em>PHP 5.5.9-1ubuntu4.14</em></li>
  <li><em>Chrome Version 47.0.2526.106 (64-bit)</em></li>
  <li>I have both port 8080 and 8090 open and accepting on both IPv4/IPv6</li>
  </ul>
  
  <p><strong>{CLIENT}</strong></p>
  
  <p>When you go to example.com:8080 it will run the following JS on initialization.</p>
  
  <p>//JS </p>
  
  <pre><code>function init(){
      var socket = new WebSocket("ws://example.com:8090"); //redirect on port 8090
      socket.send("Here's some text that the server is waiting for");
  }
  </code></pre>
  
  <p><strong>{SERVER}</strong></p>
  
  <p>//APACHE (virtual host config) *mod_proxy &amp; mod_proxy_wstunnel are installed</p>
  
  <pre><code>&lt;VirtualHost *:8090&gt;                                                            
          ServerName example:8090                                
          DocumentRoot /var/www/vhost/uploader                                                                                                                    
          ProxyPass "/sockets/" "http://example.com:8090"                                                                                            
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>//PHP (/var/www/vhost/uploader/sockets/index.php)</p>
  
  <pre><code>&lt;?php
      $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
      $ip = 'example.com';
      socket_bind($sock, $ip);
      socket_connect($sock, $ip, 8090);
      $request = 'GET / HTTP/1.1' . "\r\n" .
                 'Host: example.com' . "\r\n\r\n";
      socket_write($sock, $request);
      socket_close($sock);
  ?&gt;
  </code></pre>
  
  <p>Where I'm confused is the fact that Apache is doing the binding/listening of the socket and port so I don't know how to access it within PHP.</p>