proc_open with ajax
Posted: Sun Apr 12, 2009 9:58 am
Hi all,
I've been using PHP for many years now, and have used proc_open, popen, exec and backticks sparsely before, but this next project has me stumped.
I want to make an interactive GAP (mathematics program) session using AJAX. I thought I could do it in the following way:
1. initiate the terminal
2. check for new commands using AJAX and, if it finds any, then execute the commands.
The problem is that the pipe has to close before outputting anything: here is my code with the red section being the problematic bit.
Is there any way of outputting without closing the pipe, or getting back in to the pipe once it's closed?
Many thanks,
A
I've been using PHP for many years now, and have used proc_open, popen, exec and backticks sparsely before, but this next project has me stumped.
I want to make an interactive GAP (mathematics program) session using AJAX. I thought I could do it in the following way:
1. initiate the terminal
2. check for new commands using AJAX and, if it finds any, then execute the commands.
The problem is that the pipe has to close before outputting anything: here is my code with the red section being the problematic bit.
Code: Select all
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("file", "/tmp/error-output.txt", "a") // stderr is a file to write to
);
$process = proc_open('gap', $descriptorspec, $pipes, NULL, NULL);
if (is_resource($process)) {
[b][color=#FF0000] fwrite($pipes[0], '3+4;');[/color][/b]
[b][color=#FF0000] fclose($pipes[0]);[/color][/b]
[b][color=#FF0000] echo "<pre>".stream_get_contents($pipes[1])."</pre>";[/color][/b]
fclose($pipes[1]);
}Many thanks,
A