问题
I am trying to execute a command by using popen
and then print out its progress via AJAX. I have found this post extremely helpful and got the AJAX to script exchange working fine. The problem is that every time there is an async GET to test
from ajax, the handle on popen
is repeated. If I have the shell only run once, then the handle is no longer valid. I can't figure out how to make $handle be persistent accross requests.
public function test()
{
chdir('my dir');
$handle = popen('make install 2>&1','r');
echo fread($handle, 2096);
}
There will only be one user requesting this at a time....only used on the Admin back end of things. The output from AJAX is always, "Making install in src".
回答1:
You can't do that. You'll have to run the 'make install' process in the background (e.g. via exec()
) and redirect it's output to a file/pipe that you can read from when executing the AJAX requests.
来源:https://stackoverflow.com/questions/10511049/popen-handle-across-persistent-connections