我想用ffmpeg在php中将视频转换为.flv.目前我有这个工作,但它挂起浏览器,直到文件上传并完成.我一直在查看关于如何在后台运行exec()进程的php文档,同时使用返回的PID更新进程.这是我发现的:
//Run linux command in background and return the PID created by the OS
function run_in_background($Command, $Priority = 0)
{
if($Priority)
$PID = shell_exec("nohup nice -n $Priority $Command > /dev/null & echo $!");
else
$PID = shell_exec("nohup $Command > /dev/null & echo $!");
return($PID);
}
Run Code Online (Sandbox Code Playgroud)
还有一个技巧,我用它来跟踪后台任务是否正在使用返回的PID运行:
//Verifies if a process is running in linux
function is_process_running($PID)
{
exec("ps $PID", $ProcessState);
return(count($ProcessState) >= 2);
}
Run Code Online (Sandbox Code Playgroud)
我想创建一个单独的.php文件,然后从php cli运行以执行其中一个函数?我只需要稍微轻推一下,然后我可以从那里拿走它.
谢谢!