title: Reading data from fsockopen using fgets/fread hangs
body: <p>Here is the code that I am using:</p>
  
  <pre class="lang-php prettyprint-override"><code>if (!($fp = fsockopen('ssl://imap.gmail.com', '993', $errno, $errstr, 15)))
      echo "Could not connect to host";
  $server_response = fread($fp, 256);
  echo $server_response;
  
  fwrite($fp, "C01 CAPABILITY"."\r\n");
  while (!feof($fp)) {
      echo fgets($fp, 256);
  }
  </code></pre>
  
  <p>I get the first response: </p>
  
  <pre><code>OK Gimap ready for requests from xx.xx.xx.xx v3if9968808ibd.15 
  </code></pre>
  
  <p>but then the page times out. I have searched through stream_set_blocking, stream_set_timeout, stream_select, fread, etc. but could not get it to work. I need to read all the data that the server sends and then proceed with other commands (I would be retrieving emails using imap).</p>
  
  <p>Thanks</p>