title: ReactPHP Socket Server: What triggers the write (to client)?
body: <p>When trying to write to the client, the message is getting buffered, and in some cases, it's not being written at all.</p>
  
  <p><strong>CURRENT STATUS:</strong><br>
  When I telnet into the server, the <code>Server Ready:</code> message is readily printed as expected.</p>
  
  <p>When I send random data (other than "close"), the server's terminal nicely shows progress every second, but the clients output waits until after all the sleeping, and then prints it all at once.</p>
  
  <p>Most importantly, when sending "close", it just waits the obligatory second, and then closes without ANY writeout in the client.</p>
  
  <p><strong>GOAL:</strong><br>
  My main goal is for a quick message to be written to the client prior closing a connection.</p>
  
  <p><strong>CODE:</strong></p>
  
  <pre><code>// server.php
  $loop = React\EventLoop\Factory::create();
  
  $socket = new React\Socket\Server($loop);
  $socket-&gt;on('connection', function ($conn)
  {
      $conn-&gt;write("Server ready:\n");
  
      $conn-&gt;on('data', function ($data) use ($conn)
      {
          $data = trim($data);
  
          if( $data == 'close')
          {
              $conn-&gt;write("Bye\n");
              sleep(1);
              $conn-&gt;close();
          }
  
          for ($i = 1; $i&lt;5; $i++) {
              $conn-&gt;write(". ");
              echo '. '; 
              sleep(1);
          }
  
          $conn-&gt;write(".\n");
          echo ".\n";
  
          $conn-&gt;write("You said \"".$data."\"\n");
  
      });
  });
  $socket-&gt;listen(1337, '127.0.0.1');
  $loop-&gt;run();
  </code></pre>
  
  <p><strong>SUMMARY:</strong><br>
  Why can't I get anything written to the client before closing?</p>