I'm setting up an export feature based on the generated report, and am having problems when inserting large array rows/data to a sheet using Laravel Excel 2.1's fromArray method. Is there any alternate way to do this to not get 'Allowed memmory size exhausted'?
I already tried array_chunk method but I'm still getting the memory exhaustion error.
$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);
This is because in
php.inithere is variable namedmax_post_size. If the size of the $_POST array increases than set in php.ini, the $_POST array will be empty. You can use thisini_set('max_post_size, 50M)in your script to increase themax_post_size. This will set the max_post_size in php.ini for the current request. You can also set the size whatever you want to instead of50Mgiven in this example.Or if you permanently want to increase the
max_post_sizethen you should update the/etc/php/conf/php.inifile and setmax_post_sizeto your desired value.