title: PHP fgets() (or fread()) does not block
body: <p>I'm trying to connect to a beanstalkd server through a PHP script and to reserve jobs from an existing queue.
  I'm using the fgets() function to get responses from the deamon, expecting the script to hang unless a job is available, here's a sample code:</p>
  
  <pre><code>set_time_limit(0);
  $connection = fsockopen('localhost', 11300);
  fwrite($connection, "reserve\r\n");
  stream_set_blocking($connection, TRUE);
  fgets($connection);
  </code></pre>
  
  <p>As you can see I'm trying to force the fgets() function to be blocking and I'm setting the max_execution_time to 0 (meaning no limit), but after a while (2mins) the script returns without errors.
  I've tried to run the reserve command via telnet and it hangs as exepcted.
  I also tried to use fread() but I get the same behviour.</p>
  
  <p>Any suggestion on how to solve it?</p>