PHP - 调用外部程序并显示进度

时间:2012-10-08 17:07:30

标签: php

我有一个PHP脚本,它使表单的字段进行3次交替的程序调用,其中第一个的输出是第二个的输入,依此类推。

问题是我需要显示每个程序调用的进度,没什么好复杂的,我只想显示3条不同的消息:

  • 系统调用N等待。
  • 系统调用N执行。
  • 系统调用N完成。

我尝试使用不同的PHP函数(如exec(),popen()或proc_open()),但是对于这些函数,浏览器会等待每次调用完成。 整个系统调用不需要超过5分钟,也许是3或4,因此,在每次通话中放置一个计时器也许是好的,可能是1.5分钟,如果通话需要更多的时间,则终止系统调用,跳过以下调用并显示错误消息。

你知道吗?也许ajax和javascript的组合可以是一个解决方案。提前谢谢。

<?php
/*
  System Calls
  This file is required in another main script
  $projectPath and $projectName defined in the main script
*/

//$mainHome = getcwd();

$home = $projectPath . $projectName;
$temp = $home . "/temp/";
$calls = $temp . "CALLS";

$threads = array();

if(is_dir($temp)){
    //chdir($temp);
    $FILE = fopen($calls, "r");
    while(($call = fgetcsv($FILE)) !== FALSE) {
        //print_r($call);
        $threads[] = implode(" ", $call);
    }
}

//print_r($threads);

$descriptorspec = array(0 => array("pipe","r"),
                        1 => array("pipe","w"),
                        2 => array("file","./phpError.log","a")
);

for ($a=0; $a<count($threads); $a++) {
    print $threads[$a] . "<br/><br/>";
    exec($threads[$a])
    //$res = proc_open($threads[$a], $descriptorspec, $pipes, $temp);
}

//chdir($mainHome);

&GT;

1 个答案:

答案 0 :(得分:0)

非常感谢!最后,我开发了一个基于python CGI的解决方案,比我想象的更加静态,但符合团队的期望。

问候