I want to start a CLIPS process using proc_open function in order to interact with a CLIPS script. So if i set it like this:
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array('pipe', 'r') // 2 is STDERR for process
);
$process = proc_open('./clips -f troubleshooter.clp', $descriptorspec, $pipes);
if (is_resource($process)) {
fwrite($pipes[0], '(exit)\n');
fclose($pipes[0]);
echo stream_get_contents($pipes[1]);
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($process);
}
all seems to be fine. The process is started and ended correct
But when sending multiple input to the CLIPS shell like:
if (is_resource($process)) {
fwrite($pipes[0], '(run)\n');
fwrite($pipes[0], '(exit)\n');
fclose($pipes[0]);
echo stream_get_contents($pipes[1]);
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($process);
}
then the process is not terminated and the PHP hangs at proc_close and only when killing the process from the system monitor it finishes. Checking the stream_get_contents
output seems that the (exit) input is never sent to the process. Also when calling fclose($pipes[0]
) the CPU usage of the CLIPS process from 0% gets straight to 100%. What could be the reason for this?