使用Laravel Excel 2.1导出大型数组数据时如何修复“允许的内存大小”?

问题描述 投票:0回答:1

我正在根据生成的报告设置导出功能,并且在使用Laravel Excel 2.1fromArray方法将大型数组行/数据插入到工作表时遇到问题。有没有其他方法可以做到这一点,以免“让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);
excel laravel-5.3 maatwebsite-excel laravel-excel
1个回答
0
投票

这是因为在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设置为您想要的值。

© www.soinside.com 2019 - 2024. All rights reserved.