Hi,
I'm trying to get stream_select to work with proc_open.
At the moment it doesnt seem to get any data from the proc_open. The aim is to interact with the proc_open'ed process.
This is the code so far:
<?php
function start_proc($cmd) {
$shell = array();
$dspec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("pipe", "r")
);
$process = proc_open($cmd, $dspec, $pipes);
$shell["pipe"][0] = $pipes[0];
$shell["pipe"][1] = $pipes[1];
$shell["pipe"][2] = $pipes[2];
$shell["process"] = $process;
return $shell;
}
function end_proc($shell) {
fclose($shell["pipe"][0]);
fclose($shell["pipe"][1]);
fclose($shell["pipe"][2]);
proc_close($shell["process"]);
}
if(isset($app) {
echo "<pre>";
$shell = start_shell($app);
if(!$shell["process"]) {
echo "Failed to start $app!\n";
die();
}
$abort = 0;
$set = array($shell["pipe"][0], $shell["pipe"][2]);
while ($abort == 0) {
$set = array($shell["pipe"][0], $shell["pipe"][2]);
if (stream_select($set, $set_w = NULL, $set_e = NULL, 1, 0) > 0) {
foreach ($set as $sock) {
// Data from the local app
$data = fgets($sock, 1);
if($data == "") $abort = 1;
else echo "App: " . $data;
}
}
}
end_proc($shell);
echo "</pre>";
}
?>
Anyone got any idea??
Cheers,
Daniel.