【发布时间】:2020-12-20 19:28:47
【问题描述】:
我有一个包含 30 k 行的 CSV 文件。我已经使用maatwebsite excel 在我的 pgsql 数据库中导入 CSV。
问题是每次在数据库中上传 10k-12k 数据,然后页面给出 HTTP ERROR 500
错误:
This page isn’t working
localhost is currently unable to handle this request.
HTTP ERROR 500
我在 php.ini 中的变量下面有更改
max_execution_time=0
max_input_time=3000
post_max_size=128M
我在ReportsImport中尝试过下面的代码
class UserReport implements ToModel, WithCustomCsvSettings,WithChunkReading,WithHeadingRow
{
public function model(array $row)
{
// dd($row);
return new UserReport([
'user' => $row['username],
'amount' => $row['amount']
]);
}
public function getCsvSettings(): array
{
return [
'input_encoding' => 'UTF-8'
];
}
public function chunkSize(): int
{
return 1000;
}
}
我该如何解决这个HTTP 500 error?
错误日志:local.ERROR: Allowed memory size of 536870912 bytes exhausted
版本:Laravel 框架 7.26.1
【问题讨论】:
-
错误日志中有什么内容?
-
@Thomas local.ERROR: 允许的内存大小为 536870912 字节已用尽
-
您是否添加了
implements WithChunkReading?如果你减小 cunk 大小会发生什么? -
尝试使用作业来处理这个任务
-
您是否尝试减小块大小?如果这没有帮助,我会尝试添加Batch inserts next(除了现有的 Chunk 阅读)。