I am using https://docs.laravel-excel.com/3.1/exports. I have issue exporting 500,000 rows.
I am using queue to handle the export. Its working good for 10K records. When dealing with 500,000 records and running php artisan queue:work --timeout=86000
to execute job noting is happening.
Any idea how to make maatwebsite excel work for 500,000 records export?? Have attached the snapshot of my code.
My controller
public function getDownload(Request $request)
{
(new TagsExport)->queue('exports/tags' . date('Y-m-d H_i') . '.xlsx');
echo back()->withSuccess('Export started!');
}
My TagsExport Class
<?php
namespace App\Admin\Exports;
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\WithTitle;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\WithCustomQuerySize;
use Tag;
class TagsExport implements FromQuery,WithTitle, WithHeadings, WithMapping, WithCustomQuerySize
{
use Exportable;
/**
* Get the sheet title
*
* @return string
*/
public function title(): string
{
return 'Tags';
}
/**
* Get the header rows
*
* @return array
*/
public function headings(): array
{
return [
'id',
'Name',
];
}
public function query()
{
return Tag::query();
}
public function querySize(): int
{
$query = Tag::query();
$size = $query->count();
return $size;
}
public function chunkSize(): int
{
return 1000;
}
/**
* Get the mapped results
*
* @param Company $company
* @return array
*/
public function map($company): array
{
return [
$company->id,
$company->name,
];
}
}