popen handle across persistent connections

南楼画角 提交于 2019-12-25 06:38:50

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!