Suggestions (some you already have done)
- Upload file to server
- Queue process
- Chunk things
- You could use
updateOrCreatebut I see you have a comment about checking diff between old/new data - Index the data
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi, I'm working with a large xlsx file (more than 300k rows and 10-20 columns) and I need to check each row and than do create/update. I'm using FastExcel (rap2hpoutre/fast-excel)
$collection = (new FastExcel)->import($path);
foreach ($collection->chunk(20) as $items) {
foreach ($items as $item) {
$newData = [
'code' => $item['code'],
'name' => $item['name_org'],
'owner' => $item['fullname']
...
];
$oldData = Product::where('code', $newData['code']->first();
if(!is_null($oldData) {
// Here I check diff between old and new data
$oldData->update($newData);
} else {
Product::create($oldData);
}
}
}
This code works for me, but I'm not sure is there any field where I can improve performances? First I download a file to my storage and then get a path. There are indexes in the database table. And I tried to change chunk limit (10-500+)
Please or to participate in this conversation.