title: PHP Socket, not a valid stream resource
body: <p>I know this has been asked before, but I just can't get it to work.</p>
  
  <p>fgets() and feof() gives an error for not valid stream resource.</p>
  
  <p>socket</p>
  
  <pre><code>$socket =  fsockopen($settings['server'], $settings['port'], $errno, $errstr, 20);
  </code></pre>
  
  <p>loop</p>
  
  <pre><code>        while(!feof($socket)) {
              interface_retrieve_buffer();
  </code></pre>
  
  <p>interface_retrieve_buffer()</p>
  
  <pre><code>function interface_retrieve_buffer() {
      global $buffer,$socket;
      $buffer = fgets($socket);
  }
  </code></pre>
  
  <p>It's all done in that order using various functions, but I'm guessing the socket times out real quick and that results in the errors being sent?</p>
  
  <p>It's filling my HDD (90 GB in ~4h) and I really need to fix this, I've tried several solutions and none of them has worked.</p>
  
  <p>Thanks!</p>
  
  <p>EDIT:
  More code: <a href="http://pastebin.com/BwqJ0CJQ" rel="nofollow">http://pastebin.com/BwqJ0CJQ</a> and <a href="http://pastebin.com/gcFEAkRS" rel="nofollow">http://pastebin.com/gcFEAkRS</a></p>