Maybe this one will interest you? proc_open()
- http://www.php.net/manual/en/function.proc-open.php
And here is a handy snippet that might work for you (it is copied from the comments on the site on which I gave you the link):
<?php define(BUF_SIZ, 1024); # max buffer size define(FD_WRITE, 0); # stdin define(FD_READ, 1); # stdout define(FD_ERR, 2); # stderr function proc_exec($cmd) { $descriptorspec = array( 0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w") ); $ptr = proc_open($cmd, $descriptorspec, $pipes, NULL, $_ENV); if (!is_resource($ptr)) return false; while (($buffer = fgets($pipes[FD_READ], BUF_SIZ)) != NULL || ($errbuf = fgets($pipes[FD_ERR], BUF_SIZ)) != NULL) { if (!isset($flag)) { $pstatus = proc_get_status($ptr); $first_exitcode = $pstatus["exitcode"]; $flag = true; } if (strlen($buffer)) echo $buffer; if (strlen($errbuf)) echo "ERR: " . $errbuf; } foreach ($pipes as $pipe) fclose($pipe); $pstatus = proc_get_status($ptr); if (!strlen($pstatus["exitcode"]) || $pstatus["running"]) { if ($pstatus["running"]) proc_terminate($ptr); $ret = proc_close($ptr); } else { if ((($first_exitcode + 256) % 256) == 255 && (($pstatus["exitcode"] + 256) % 256) != 255) $ret = $pstatus["exitcode"]; elseif (!strlen($first_exitcode)) $ret = $pstatus["exitcode"]; elseif ((($first_exitcode + 256) % 256) != 255) $ret = $first_exitcode; else $ret = 0; proc_close($ptr); } return ($ret + 256) % 256; } if (isset($argv) && count($argv) > 1 && !empty($argv[1])) { if (($ret = proc_exec($argv[1])) === false) die("Error: not enough FD or out of memory.\n"); elseif ($ret == 127) die("Command not found (returned by sh).\n"); else exit($ret); } ?>
source share