首页 博客 娱乐 图库 新闻 体育 视频

超大数据量导出不超时,内存不溢出方法

          "被叫号码", 'start_stamp' => "开始时间", 'end_stamp'=> "结束时间",'answer_stamp'=>"应答时间", 'billsec' => "接听时长",'app_billing_unit' => "计费单元",'billing_type'=>'计费类型','bill_num'=>'计费次数','bill_total'=>"费用",'hangup_cause'=>'挂机原因','call_key'=>"客户按键",'requests_text'=>"推送结果",'call_pbx_node'=>"呼叫节点"); // 输出Excel列名信息$head = array("电子邮件"); foreach ($title as $i => $v) { // CSV的Excel支持GBK编码,一定要转换,否则乱码 $head[$i] = iconv('utf-8', 'gbk', $v); } fputcsv($fp, $head); // 计数器 $cnt = 0; // 每隔$limit行,刷新一下输出buffer,不要太大,也不要太小 $limit = 1000; $db = DBHelper::loadDB(); $sum = $db->getOne("select count(1) as count from ($sql) as t "); $limit = 1000; if($sum) { $iEnd = ceil($sum / $limit); for ($i = 0; $i < $iEnd; $i++) { $dataList = $db->getAll($sql_se. " limit " . strval($i * $limit) . "," . $limit); foreach($dataList as $key=>$val){ $cnt++; if (3000 == $cnt) { //刷新一下输出buffer,防止由于数据过多造成问题 ob_flush(); flush(); $cnt = 0; } $row[]=@iconv('utf-8', 'gbk', $val['caller_id_number']); $row[]=@iconv('utf-8', 'gbk', $val['start_stamp']); $row[]=@iconv('utf-8', 'gbk', $val['end_stamp']); $row[]=@iconv('utf-8', 'gbk', $val['answer_stamp']); $row[]=$this->changeTimeType($val['billsec']); $row[]=@iconv('utf-8', 'gbk', $val['app_billing_unit']); if($val['billing_type']==1){ $row[]=@iconv('utf-8', 'gbk',"6秒计费"); }else if($val['billing_type']==2){ $row[]=@iconv('utf-8', 'gbk',"1分钟计费"); }else if($val['billing_type']==3){ $row[]=@iconv('utf-8', 'gbk',"18秒计费"); }else if($val['billing_type']==4){ $row[]=@iconv('utf-8', 'gbk',"12秒计费"); }else{ $row[]=""; } $row[]=@iconv('utf-8', 'gbk', $val['bill_num']); $row[]=@iconv('utf-8', 'gbk', $val['bill_total']); $h=""; if($val['hangup_cause']=="NORMAL_CLEARING"){ $h="正常挂断"; }else if($val['hangup_cause']=="CAlL_REJECTED"){ $h="用户拒绝"; }else if($val['hangup_cause']=="NO_ANSWER"){ $h="用户无应答"; }else if($val['hangup_cause']=="NO_USER_RESPONSE"){ $h="用户无响应"; }else if($val['hangup_cause']=="NONE"){ $h="正常挂断"; }else if($val['hangup_cause']=="NORMAL_TEMPORARY_FAILURE"){ $h="呼叫线路超时"; }else if($val['hangup_cause']=="NORMAL_UNSPECIFIED"){ $h="线路不通"; }else if($val['hangup_cause']=="RECOVERY_ON_TIMER_EXPIRE"){ $h="媒体超时"; }else if($val['hangup_cause']=="UNALLOCATED_NUMBER"){ $h="线路不通"; }else if($val['hangup_cause']=="USER_BUSY"){ $h="用户忙"; }else{ $h="呼叫未应答"; } $row[]=@iconv('utf-8', 'gbk', $h); $row[]=@iconv('utf-8', 'gbk', $val['call_key']); $row[]=@iconv('utf-8', 'gbk', $val['requests_text']); $row[]=@iconv('utf-8', 'gbk', $val['call_pbx_node']); fputcsv($fp, $row); unset($row); } } } exit(); } ?>


除非特别注明,本站所有文字均为原创文章,作者:luojie

No Comment

留言

电子邮件地址不会被公开。 必填项已用*标注

感谢你的留言。。。