【问题标题】:PHP Ajax jQuery UI Progressbar for Long Running MySQL operation用于长时间运行 MySQL 操作的 PHP Ajax jQuery UI 进度条
【发布时间】:2013-11-30 18:35:41
【问题描述】:

我有一个 PHP 脚本需要很长时间才能执行,因为每个操作都必须对另一个网站进行 SOAP 调用。我想添加一个进度条指示器,以便我可以看到此脚本的完成百分比。

我相信这样做的方法是执行一个异步 Ajax 调用来执行 PHP,然后再进行另一个 Ajax 调用来更新完成百分比。但是我在把这些放在一起时遇到了很多问题。

目前我只有这个:

<script language='Javascript'>

$().ready(init);

function init() {       
    $.get('importStatement.php');           
}

$(function() {
$( "#progressbar" ).progressbar({
  value: 0
});
});

</script>

<div id="progressbar"></div>

我的输出完成百分比 ($i) 的 PHP 脚本:

$current_day = $date->today;
$days_to_read = 45;
// Scroll through the last $days_to_read dates and import a statement for that day
for ($i = 0; $i < $days_to_read; $i++) {
    $statement_date = $date->convertToMysql($current_day);
    $bank->importStatement($statement_date, true);
    $percent = intval($i/($days_to_read-1) *100).  "%";
    // disable caching
    header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
    header('Cache-Control: no-cache, must-revalidate');
    header('Pragma: no-cache');
    header('Expires: Mon, 26 Jul 1991 05:00:00 GMT');  // disable IE caching
    header('Content-Type: text/plain; charset=utf-8');
    echo $i;    
    $current_day = $date->decreaseDay($current_day);
}

我为什么要战斗是因为输出进度的importStatement.php“断开”或与进度条无关。进度条需要从这个脚本输入。有人可以指导我吗?

【问题讨论】:

    标签: php jquery mysql ajax jquery-ui-progressbar


    【解决方案1】:

    我之前已经实现过这样的进度条(不确定这是最好的方法,但它对我有用)。

    有另一个 MySQL 表来存储进度。

    当您开始实际报告时,请在“进度”表中创建一个带有作业 ID 的条目。让长时间运行的 PHP 脚本不断更新“进度”表,而不是将进度回显到屏幕上。将您的 AJAX 进度条指向一个快速 PHP 脚本,该脚本接受作业 ID 并回显数据库中的进度。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多