title: PHP reading shell_exec live output
body: <p>I'm just experimenting with PHP and <code>shell_exec</code> on my Linux server. It's a really cool function to use and I am really enjoying it so far. Is there a way to view the live output that is going on while the command is running?</p>
  
  <p>For example, if <code>ping stackoverflow.com</code> was run, while it is pinging the target address, every time it pings, show the results with PHP? Is that possible?</p>
  
  <p>I would love to see the live update of the buffer as it's running. Maybe it's not possible but it sure would be nice.</p>
  
  <p>This is the code I am trying and every way I have tried it always displays the results after the command is finished.</p>
  
  <pre><code>&lt;?php
  
    $cmd = 'ping -c 10 127.0.0.1';
  
    $output = shell_exec($cmd);
  
    echo "&lt;pre&gt;$output&lt;/pre&gt;";
  
  ?&gt;
  </code></pre>
  
  <p>I've tried putting the <code>echo</code> part in a loop but still no luck. Anyone have any suggestions on making it show the live output to the screen instead of waiting until the command is complete?</p>
  
  <p>I've tried <code>exec</code>, <code>shell_exec</code>, <code>system</code>, and <code>passthru</code>. Everyone of them displays the content after it's finished. Unless I'm using the wrong syntax or I'm not setting up the loop correctly.</p>