如何使shell exec在后台运行,而php继续 [英] How to make shell exec run in background while php continues
问题描述
我有一个 ffmpeg
在PHP文件中进行视频转换,它的工作原理。问题是需要一分钟才能完成。我认为这可能很容易,但是当我只使用一个命令(例如没有mp4box的单程转换)时,我只能在后台工作,这样
I have ffmpeg
doing a video conversion in a PHP file and it works as it should. The problem is it takes up to a minute for this to finish. I thought it might be easy to do but I can only get it to work in the background when I use just one command (eg single pass conversion without mp4box) like this
exec("nohup " . $ffmpegPath . " -i " . $srcFile . " -f mp4 -vcodec libx264 -crf 27 -s " . $srcWidth . "x" . $srcHeight . " -an -r 20 " . $destFile . ".mp4 > /dev/null 2>&1 &");
问题是我需要使用三个不同的命令来进行适当的转换。到目前为止,我的命令在PHP文件中看起来像这样,它的工作原理很大,但延迟很大:
The problem is I need to use three different commands to do a proper conversion though. So far my commands look like this in the PHP file and it works, but with a massive delay:
exec($ffmpegPath . " -y -i " . $srcFile . " -f mp4 -pass 1 -passlogfile " . $video_pass_log . " -vcodec libx264 -vpre ipod640 -b:v 2M -bt 4M -an " . $destFile . ".mp4");
exec($ffmpegPath . " -y -i " . $srcFile . " -f mp4 -pass 2 -passlogfile " . $video_pass_log . " -vcodec libx264 -vpre ipod640 -b:v 2M -bt 4M -acodec libfaac -ac 2 -ar 44100 -ab 96k " . $destFile . ".mp4");
exec($mp4boxpath . " -tmp /tmp -hint " . $destFile . ".mp4");
PHP继续执行时如何使shell exec运行在后台?
How can I make the shell exec run in background while PHP continues?
推荐答案
添加> / dev / null 2> / dev / null&
将删除输出并在另一个进程中运行命令(&
创建新的进程,>
和 2>
重定向正常和错误输出)
Adding > /dev/null 2>/dev/null &
will remove the output and runs the command in another process (the &
creates the new process, the >
and 2>
redirects the normal and error output)
这篇关于如何使shell exec在后台运行,而php继续的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!