php exec如何查看进度 [英] php exec how to see progress

查看:212
本文介绍了php exec如何查看进度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行2个exec的php脚本.

I have a php script that run 2 exec.

exec(".....", $output, $return1);
echo $return1;
exec(".....", $output, $return2);
echo $return2;

这2个执行程序各需要1分钟才能运行. 运行此脚本时,我等待2分钟,结果为"00". 可以,但是我想看到$return1; 1分钟后,请参阅$return2 1分钟后. 我必须使用Ajax/js吗? 实际上,我会制作一个进度条,当第一个执行程序完成时=> 50%,第二个执行程序执行时=> 100%

This 2 exec take 1 minute each to run. When I run this script, I'm waiting 2 minutes and it result "00". It's OK but I would like to see $return1; after 1 minute and see $return2 after 1 minute. I have to use Ajax / js ? In fact, I would make a progress bar, when first exec is done => 50% when second exec is done => 100%

非常感谢您的帮助!

开始解决方案:

类似这样的东西:

define.php:

define.php :

setInterval(function() {
$.ajax({
    type: "GET",
    url: 'convert.php?file='+id_file,
    cache:false,
    success:function(result){
        $('.content_box').html(result);

    }
});

}, 3000);

Convert.php:

Convert.php :

exec(convert id_file.pdf id_file.jpg, $output, $return1);
echo $return1;
exec(convert -resize50x50 id_file.jpg id_file_thumb.jpg, $output, $return2);
echo $return2;

但是它运行时没有回调和不间断!

But it run without callback and non-stop!

推荐答案

是的,您必须使用AJAX-只需保持脚本原样,就需要另一个脚本来报告原始脚本的进度和/或部分结果脚本.原始脚本可以使用$ _SESSION传递进度/部分结果信息,这是最简单的解决方案.

Yes, you have to use AJAX - just keep your script as is, and you will need another script that reports the progress and/or partial results of the original script. The original script can use $_SESSION to pass the progress / partial results information, that's the simplest solution.

或者,您可以使用AJAX请求,不仅报告进度/部分结果,还可以按照Zar的建议逐步执行操作.但是这种方法不太灵活.这些阶段可能共享一些全局数据,因此最好是两个脚本都在一个脚本运行中运行.因此,我在第一段中介绍的方法更为可行.

Or, you could use AJAX request not just to report progress/partial results, but to run the action stage by stage, as Zar is probably proposing. But this approach is less flexible; there might be some global data that the stages share, so it is better if they are both within one script run. So the approach I sketched in the 1st paragraph is more viable.

这篇关于php exec如何查看进度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆