无需等待即可从 php 执行 bash 脚本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5420941/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 23:40:10  来源:igfitidea点击:

execute bash script from php without waiting

phpbash

提问by mjspier

I execute a bash script from php with shell_exec. But the php script waits until the shell script is finished.

我用 shell_exec 从 php 执行一个 bash 脚本。但是 php 脚本会等到 shell 脚本完成。

Can I somehow call the bash script without waiting. Both:

我可以不等待就以某种方式调用 bash 脚本吗?两个都:

exec
shell_exec

are waiting until the bash script is finished. I'm running linux btw.

正在等待 bash 脚本完成。顺便说一句,我正在运行 linux。

采纳答案by ChrisH

This has to work:

这必须工作:

exec('/your/command /dev/null 2>/dev/null &');

exec('/your/command /dev/null 2>/dev/null &');

回答by sharpner

when calling your bash script append & so it will run in the background that's the easiest way if you don't need any output

当调用你的 bash 脚本 append & 所以它会在后台运行,如果你不需要任何输出,这是最简单的方法

shell_exec("/bin/bash /path/to/script.sh &");