-1

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

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

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

我正在尝试使用 exec()、popen() 或 proc_open() 等不同的 PHP 函数来做到这一点,但对于这些函数,浏览器会等待每个调用完成。整个系统调用不会超过 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);

?>

4

1 回答 1

0

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

问候

于 2012-10-10T20:51:56.860 回答