我需要执行一个 shell 脚本。问题是我想这样做
$Command = "nohup cvlc input --sout '#transcode {vcodec=h264,acodec=mp3,samplerate=44100}:std{access=http,mux=ffmpeg{mux=flv},dst=0.0.0.0:8083/".output"}' &";
$str = shell_exec($Command);
我不希望它等到命令完成,我希望它在后台进程中运行。
我不想要另一个 php 线程,因为它会超时,该命令可能需要长达 3 小时才能完成。
您可以尝试使用如下函数在后台运行命令:
function exec_bg($cmd) {
if (substr(php_uname(), 0, 7) == "Windows"){
pclose(popen("start /B ". $cmd, "r"));
}
else {
exec($cmd . " > /dev/null &");
}
}
这会使您的 shell 命令运行,但 php 流程继续。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)