Php 拉威尔出口500000行
我正在使用。我导出500000行有问题。 我正在使用队列处理导出。它对10K记录很有用。处理500000条记录并运行Php 拉威尔出口500000行,php,laravel,export-to-excel,laravel-7,maatwebsite-excel,Php,Laravel,Export To Excel,Laravel 7,Maatwebsite Excel,我正在使用。我导出500000行有问题。 我正在使用队列处理导出。它对10K记录很有用。处理500000条记录并运行php artisan queue:work--timeout=86000执行作业时,注意到正在发生 你知道如何使maatwebsite excel能够导出500000条记录吗??已附加我的代码的快照 我的控制器 public function getDownload(Request $request) { (new TagsExport)->queue('expor
php artisan queue:work--timeout=86000执行作业时,注意到正在发生
你知道如何使maatwebsite excel能够导出500000条记录吗??已附加我的代码的快照
我的控制器
public function getDownload(Request $request)
{
(new TagsExport)->queue('exports/tags' . date('Y-m-d H_i') . '.xlsx');
echo back()->withSuccess('Export started!');
}
我的TagsExport类
<?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,
];
}
}
如果您的代码在10.000个寄存器中运行良好,但在50.000行中中断,我认为生成整个导出文件所需的时间比您预期的要长,而且对您来说似乎什么都没有发生,但队列没有足够的时间来处理所有这些
你真的需要一个大文件吗?你不能把垃圾分成多张纸吗
[1~25000]
[25001 ~ 50000]
[50001 - 100000]
And so on...
这也可能与PHP允许使用的内存量有关(在本例中内存不足),请尝试在PHP.ini中对其进行更改,并让您的工作人员再试一次
谢谢卢安,我用的是-1的内存限制,我认为队列没有足够的时间执行,所以我放了。超时=86000以显式使其在86000 se下工作