Executing shell commands with instant output in PHP

<?php // immediate output to the browser function _cmd_callback($buffer){ return '<span>'.$buffer.'</span>'; // For Crome, Opera, IE; } function cmd($cmd, $callback=''){ while (ob_end_clean()); header('Content-Encoding: none;'); ob_implicit_flush(1); ob_start($callback ? $callback : '_cmd_callback', 2); echo str_repeat(' ', 4096*10).'<pre><code>'; // for IE $last_line = passthru(escapeshellcmd($cmd), $retval); if ($retval) { echo "<br>Error!"; error('passthru '.escapeshellcmd($cmd)); } ob_end_flush(); }