我正在根据生成的报告设置导出功能,并且在使用Laravel Excel 2.1
的fromArray
方法将大型数组行/数据插入到工作表时遇到问题。有没有其他方法可以做到这一点,以免“让memmory大小耗尽”?
我已经尝试过array_chunk
方法,但我仍然得到内存耗尽错误。
$reportData = $this->report->run(); // Depending on the filters of the report, it can get upto 20,000 rows.
$headers = Input::get('selectedcolumns');
$data = [];
foreach($report['data'] as $value) {
$row = [];
foreach($headers as $header) {
$row[$header['label']] = $value[$header['name']];
}
$data[] = $row;
}
return Excel::create('Excel', function($excel) use($data) {
$excel->sheet('Sheet1', function($sheet) use($data) {
->sheet->fromArray($data);
});
})->store('xls', false, true);
这是因为在php.ini
中有一个名为max_post_size
的变量。如果$ _POST数组的大小增加而不是php.ini中的设置,则$ _POST数组将为空。您可以在脚本中使用此ini_set('max_post_size, 50M)
来增加max_post_size
。这将在php.ini中为当前请求设置max_post_size。您也可以设置任何您想要的大小,而不是在此示例中给出的50M
。
或者,如果您永远想要增加max_post_size
,那么您应该更新/etc/php/conf/php.ini
文件并将max_post_size
设置为您想要的值。