php+JS进度条

<?php
ini_set('max_execution_time','0');//设置本页面加载时间无限制

echo "<div style='border: 1px solid grey;1000px;height:30px;overflow:hidden'>
<div style='background-color:red;0px;height:100%;text-align:center;color:white' id='div'></div>
</div>
<p>正在操作第:<span id='p'></span>个用户</p>
";
$user=[
'0'=>['id'=>1], '1'=>['id'=>2], '2'=>['id'=>3], '3'=>['id'=>4], '4'=>['id'=>5], '5'=>['id'=>6], '6'=>['id'=>7], '7'=>['id'=>8], '8'=>['id'=>9], '9'=>['id'=>10], '10'=>['id'=>11], '11'=>['id'=>12], '12'=>['id'=>13], '13'=>['id'=>14], '14'=>['id'=>15], '15'=>['id'=>16], '16'=>['id'=>17], '17'=>['id'=>18], '18'=>['id'=>19]
];
$total = count($user);
function send($id,$total)
{
$b=($id/$total)*100;
$a = round($b,1);
if($a>100){ $a=100;}
echo "<script> document.getElementById('div').style.width='$a%'; document.getElementById('p').innerHTML=$id; document.getElementById('div').innerHTML='$a%'; </script>";
}
foreach ($user as $key => $value){
sleep(1);//模拟耗时
print str_repeat(" ", 4096);//清楚缓存数据释放的容量
flush();
send($value['id'],$total);
}

ob_end_flush();

  

原文地址:https://www.cnblogs.com/qqlong/p/8359227.html