0

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".

Community
  • 1
  • 1
Justin
  • 183
  • 1
  • 1
  • 11
  • It's not really the `popen` handle you need to keep open, it's the PHP script itself you need to keep running. Are you doing this in any way? – deceze May 09 '12 at 07:17

1 Answers1

2

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.

Narf
  • 14,600
  • 3
  • 37
  • 66