dongyan6910 2010-03-29 18:31
浏览 90

在php中运行bash脚本

I have two computers. On the first computer I have apache running with all my web code. On the second computer I have large amounts of data stored with a retrieval script (the script usually takes hours to run). I am essentially creating a web UI to access this data without any time delay.

so I call:

exec("bash initial.bash");

this is a driver script that is in my Apache folder. It calls the script on the other computer. calling: ssh otherMachine temp.bash&

this script invokes the data retrieval script on the second computer.

If I call initial.bash in the terminal, everything works smoothly and successfully, but if I call it in my PHP file, then all my commands in initial.bash run, with the exception of ssh otherMachine temp.bash&. I put the & at the end of that, so that temp.bash will run in the background, since it does take a few hours to complete.

I am not sure why the nested script is not running when invoked by Apache. Is there a better alternative than using exec or shell_exec to call a script, which ultimately calls another script. The reason I don't call a script on the second machine directly is because of the time it takes the program to run. Shell_exec does not render the php page until the script is complete.

  • 写回答

3条回答 默认 最新

  • dsjzmrz78089 2010-03-29 18:36
    关注

    My guess is that SSH doesn't like the user php is running under? You say it works fine from the terminal - are you logged in as the same php user?

    You might also find a message queue of some sort a better solution.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog