目录
需求
导出几十万左右的数据导excel表
问题
- 使用phpexcel等插件,碰到数据量大很慢,可能能花半个小时以上
- 数据量大查询慢
- 内存不足
- 执行超时
解决
- 使用原生csv导出
- 设置脚本超时和内存,进行加大内存,不限制超时时间
- 进行分页查询
/**
* 分批导出
* @param Request $request
*/
public function bpOut(Request $request){
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
ini_set("memory_limit", "2048M");
set_time_limit(0);
$lot = $request->get('lot');
$type = $request->get('type');
if($type == 'increment'){
$filename ="订单日增量表格_".$lot.".c