[英]Executing an exec() or system() in PHP and do not wait for output
我想从PHP脚本中触发eider exec()或system()中的shell命令,但这是一个需要一段时间才能完成的任务,有没有办法触发它并继续运行PHP页面加载而没有延迟?
编辑:我在CentOS 6,PHP 5.3上
取决于您使用的操作系统。
对于linux:
pclose(popen("php somefile.php &","r"));
注意最后的放大器(非常重要)。
对于Windows:
pclose(popen("start php.exe somefile.php","r"));
这里start
关键字很重要。
希望这可以帮助。
这不能直接回答您的问题,但您应该考虑使用cron作业或使用Beanstalkd等队列在后台进程中进行视频转换。
这样,您可以在后台堆叠ffmpeg工作,而不会阻止您的Web服务器。
我过去在这两种方法(cron / queue)上取得了很大的成功。
关于后台流程的其他一些帖子:
您可能会发现一些有用的工具:
http://kevin.vanzonneveld.net/techblog/article/create_daemons_in_php/
我所做的:
public function post_create()
{
ob_end_clean();
header("Connection: close");
ignore_user_abort(); // optional
ob_start();
echo "Tell ajax to gtfo!";
$size = ob_get_length();
header("Content-Length: $size");
ob_end_flush(); // Strange behaviour, will not work
flush(); // Unless both are called !
// Do processing here
}
好吧,使用ajax请求激活exec部分......然后继续执行其他任务
这应该工作:
shell_exec("nohup yourcommand > /dev/null 2> /dev/null &");
编辑:对不起,不知道我为什么要排除&把它放到bg 2>将STDOUT和STDERR重定向到/ dev / null。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.