title: PHP - TCP/IP fsockopen
body: <p>I was wondering if anyone has had any experience with this before. I'm trying to write a simple script that will continously read data from the TCP/IP stream but for some reason or another the script reads in a bunch of data, writes it out and then just stops.</p>
  
  <pre><code>$fp = fsockopen("xxxx", 3000, $errno, $errstr, 5);
  if (!$fp) {
      echo "$errstr ($errno)&lt;br /&gt;\n";
  } else {
      while (!feof($fp)) {
          echo fgets($fp, 128)."\n";
          fflush($fp);
      }
      fclose($fp);
  }
  </code></pre>
  
  <p>I'd like it to have a constant flow to it, rather then echo out a bunch of data then wait 30 seconds and output a bunch more data. Anyone have any ideas?</p>
  
  <p>---- EDIT ----</p>
  
  <p>ZMQ Code</p>
  
  <pre><code>include 'zmsg.php';
  
  $context = new ZMQContext();
  $client = new ZMQSocket($context, ZMQ::SOCKET_DEALER);
  
  // Generate printable identity for the client
  $identity = sprintf ("%04X", rand(0, 0x10000));
  $client-&gt;setSockOpt(ZMQ::SOCKOPT_IDENTITY, $identity);
  $client-&gt;connect("tcp://xxxx:3000");
  
  $read = $write = array();
  $poll = new ZMQPoll();
  $poll-&gt;add($client, ZMQ::POLL_IN);
  
  $request_nbr = 0;
  while (true) {
      // Tick once per second, pulling in arriving messages
      for ($centitick = 0; $centitick &lt; 100; $centitick++) {
          $events = $poll-&gt;poll($read, $write, 1000);
          $zmsg = new Zmsg($client);
          if ($events) {
              $zmsg-&gt;recv();
              echo $zmsg-&gt;body()."\n";
              //printf ("%s: %s%s", $identity, $zmsg-&gt;body(), PHP_EOL);
          }
      }
      $zmsg = new Zmsg($client);
      //$zmsg-&gt;body_fmt("request #%d", ++$request_nbr)-&gt;send();
  }
  </code></pre>