我有一个 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 是“断开连接”或与进度条无关。进度条需要从这个脚本输入。有人可以指导我吗?