场景:
- 我有一个 PHP 脚本(通过网络访问),它生成一个 shell 脚本,即使在请求结束后也需要继续运行。
- 我需要将输出发送到磁盘上的文件(即“./script.sh > run.log”)
我尝试的每一种方法似乎都会导致 PHP 仍在等待 shell 脚本完成执行。我尝试过的方法:
nohup ./script.sh > run.log &
nohup ./script.sh > run.log 2>&1
nohup ./script.sh > run.log 2>&1 &
./script.sh &
./script.sh > run.log 2>&1
./script.sh > run.log &
我认为我可能遗漏了一些非常明显的东西。有什么想法吗?
最佳答案
我认为您可以通过使用脚本启动一个 screen
实例来实现这一点:
screen -d -m 'bash ./script.sh > run.log'
关于php - 从 PHP 在后台运行 shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36209175/