I prefer to use popen for this kind of task. Especially for long commands, because you can receive output in turn and send it to the browser, so there is less chance of a timeout. Here is an example:
$p = popen('script.cmd', 'r'); if ($p) { while (!feof($p)) echo gets($p); // get output line-by-line pclose($p); }
source share