| $stid = isset($_GET['stid'])?$_GET['stid']:0;$endid = $stid + 100;$maxid = 10000;function dosomething(){//要时间比较多的操作……}$sql_string=”select *  from `table`  where id>’$stid’ and id<=’$endid’ order by id”;$datas = getdata_bysql($sql_string);foreach($datas as $data){//处理数据…..echo $id.” 处理完成. ”;
if($id>=$maxid){exit;}}if($stid<=$maxid){$stid = $stid + 100;$url=”action.php?stid=$stid”;echo $url;echo ‘’;}?> 
 其中的dosomething()是一个耗时操作。这里我们通过限制id范围来减少运行时间,运行完后通过javascript的跳转来自动运行下一步。
这样,每处理一批数据就可以知道结果,如果中断也知道问题出在那里。 |