title: ZeroMQ Pub/sub with PHP fails on single web connection but works with loop
body: <p>I have this simple code for a ZeroMQ pub/sub setup in PHP , and the strange part is it doenst work for single (1x) web Requests, when I comment out the while(true) { //code } it doesn't work the web client doesn't receive the single request, but when the publisher->send() is invoked inside the loop the web client receives all the message normally.</p>
  
  <p><strong>ZeroMQ PHP Publisher</strong></p>
  
  <pre><code>    &lt;?php
      header('Content-Type: text/event-stream');
      header('Cache-Control: no-cache'); // recommended to prevent caching of event dat
      header("Connection: keep-alive");
  
      $port=8899; 
      //  Prepare our context and publisher
      $context = new ZMQContext();
      $publisher = $context-&gt;getSocket(ZMQ::SOCKET_PUB);
      $publisher-&gt;bind("tcp://*:".$port);
  
      echo "Running..Serving test data on TCP port $port every 1 s \n &lt;hr&gt;";
      while (true) {  //doesn't work when this line is commented out
  
          $count++;
          $json=json_encode(array($count, PHP_RELEASE_VERSION, PHP_OS , $_SERVER['PHP_SELF'], Date("h:i:s m-d-Y")  ) );
          $publisher-&gt;send( $json);
          sleep(1);
          echo "+";   
          ob_flush();
         flush();  //send out to browser
       }
      ?&gt;
  </code></pre>
  
  <p><strong>ZeroMQ PHP Subscriber</strong></p>
  
  <pre><code>&lt;?php
  header('Cache-Control: no-cache'); // recommended to prevent caching of event dat
  header("Connection: keep-alive");
  
  $context = new ZMQContext();
  $subscriber = $context-&gt;getSocket(ZMQ::SOCKET_SUB);
  $subscriber-&gt;setSockOpt(ZMQ::SOCKOPT_SUBSCRIBE, '');
  
  $port=8899;
  $subscriber-&gt;connect('tcp://localhost:'.$port);
  
  while(true) {
  
      echo "&lt;br&gt;Waiting for message " ;
      $string = $subscriber-&gt;recv();
      echo "&lt;br&gt;Received ".$string ;
      ob_flush();
      flush();
   }
  
  ?&gt;
  </code></pre>
  
  <p>I suspect it has to do with when the PHP script ends the ZeroMQ message is never sent or closed for single requests..</p>