[Bug]: #3494
-
Is the bug applicable and reproducable to the latest version of the package and hasn't it been reported before?
What version of Laravel Excel are you using?3.1.35 What version of Laravel are you using?8.77.1 What version of PHP are you using?8.0 Describe your issueExporting a big database dataset from a query to a file should use DB chunking and file streaming and hence not cause a memory issue, but when trying to do so (even with the local disk) then the following memory issue occurs:
The funny part is that using How can the issue be reproduced?Steps to reproduce
$export = new \App\Exports\ExampleExport();
$filename = 'test.csv';
$disk = 's3';
// Should work, but does not work :(
//\Excel::store($export, $filename, $disk);
// Pure PHP way - works
$tmpFile = uniqid().'.csv';
$this->commentNote('Exporting to temporary file', "{$filename}");
$resource = fopen(storage_path('app/'.$tmpFile), 'w'); // will use the 'local' disk
$bar = $this->output->createProgressBar($export->query()->count());
$export->query()->chunk($export->chunkSize(), function ($chunk) use ($resource, $bar) {
foreach ($chunk as $row) {
fputcsv($resource, (array) $row);
$bar->advance();
}
});
fclose($resource);
$bar->finish();
$this->newLine();
// $this->commentNote('Moving', "{$tmpFile} to {$disk}::{$filename}");
// $this->moveFile('local', $disk, $tmpFile, $filename);
// Storage::disk('local')->delete($tmpFile); What should be the expected behaviour?The expected behaviour would be that running the top code was also able to write the export to the $export = new \App\Exports\ExampleExport();
\Excel::store($export, 'test.csv., 'local); // or to an s3 disk |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
There's unfortunately not a lot we can do about that here. The performance issue is within PhpSpreadsheet which builds an entire array of cells (to be interchangable with Excel types), something that you circumvent if you do a If you need a high performance export, use fputcsv (or an abstraction like league/csv). (We might open source our drop-in csv export package in the future, however for now that is closed source) |
Beta Was this translation helpful? Give feedback.
There's unfortunately not a lot we can do about that here. The performance issue is within PhpSpreadsheet which builds an entire array of cells (to be interchangable with Excel types), something that you circumvent if you do a
fputcsv
directly. (Only current chunk is kept into memory). PhpSpreadsheet inserts the entire array of cells at once, not row per row. (So very logical that the performance is very different)If you need a high performance export, use fputcsv (or an abstraction like league/csv). (We might open source our drop-in csv export package in the future, however for now that is closed source)