title: Can't read from socket (hangs)
body: <p>I am using PHP to connect to a local C++ socket server to keep state between a web app and a couple of daemons.  I can send data to the socket server, but not receive from it; it just blocks on <code>socket_read()</code> and hangs indefinitely.  Am I forgetting something dumb (like a NULL character or a different combination of newline characters)?  The PHP is below:</p>
  <pre><code>socket_connect($sock, $addr, $port); 
  socket_write($sock, 'Hello world');
  $str = '';
  while($resp = socket_read($sock, 1000))
      $str .= $resp;
  socket_close($sock);
  die(&quot;Server said: {$str}&quot;);
  </code></pre>
  <p>The related part of the socket server is below (note that the <code>&lt;&lt;</code> and <code>&gt;&gt;</code> operators are overloaded):</p>
  <pre><code>std::string data;
  sock &gt;&gt; data;
  sock &lt;&lt; data &lt;&lt; std::endl;
  </code></pre>
  <p>Where <code>&gt;&gt;</code> calls <code>Socket::recv(std::string&amp;)</code> and <code>&gt;&gt;</code> calls <code>Socket::send(const std::string&amp;)</code>.</p>
  <p>This works fine from (for example) telnet, but PHP doesn't want to play nice.  Any thoughts/suggestions are appreciated.</p>