0

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);
MiniDr
  • 191
  • 1
  • 11

1 Answers1

0

This is because in php.ini there is variable named max_post_size. If the size of the $_POST array increases than set in php.ini, the $_POST array will be empty. You can use this ini_set('max_post_size, 50M) in your script to increase the max_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 of 50M given in this example.

Or if you permanently want to increase the max_post_size then you should update the /etc/php/conf/php.ini file and set max_post_size to your desired value.

Khuram
  • 1,820
  • 1
  • 26
  • 33