title: Php socket headers from client
body: <p>I have a socket server that handles connections. Here I have a <code>doHandshake</code> method.</p>
  
  <pre><code>function doHandshake($received_header, $client_socket_resource, $host_name, $port) {
      var_dump($received_header);
      // do stuf here with header
  }
  </code></pre>
  
  <p>When I want to connect from <strong>javascript client</strong>, It works fine, and prints all headers such as <code>Sec-WebSocket-Key</code>. This is how I use doHandShake method in socket server:</p>
  
  <pre><code>$header = socket_read($newSocket, 1024);
  $chatHandler-&gt;doHandshake($header, $newSocket, HOST_NAME, PORT);
  </code></pre>
  
  <p>In the other hand I have a php client. When I connect from php client, header is a string that I send to server not a real header. Here is my client socket in php:</p>
  
  <pre><code>$host    = "127.0.0.1";
  $port    = 8090;
  $message = "Hello Server";
  echo "Message To server :".$message;
  // create socket
  $socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");
  // connect to server
  $result = socket_connect($socket, $host, $port) or die("Could not connect to server\n");  
  // send string to server
  socket_write($socket, $message, strlen($message)) or die("Could not send data to server\n");
  // get server response
  
  $result = socket_read ($socket, 1024) or die("Could not read server response\n");
  echo "Reply From Server  :".$result;
  // close socket
  socket_close($socket);
  </code></pre>
  
  <p>Any idea how to send socket headers in php client??</p>
  
  <p><strong>Note:</strong> This is done automatically in <strong>javascript client</strong>.</p>