Of course it does, you add to the $batch variable every time you itterate orver the next chunk
$batch->add($calculationJob);
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
The users list have 160000 Records and its chunked to created 1000 per batch. The userjob Class has no processing logic and returns just 0. When I remove the batch in the below code and check consumption, the memory is just 4mb., but on adding the batches the memory keeps crawling up to 4gb,looks like all the batches are loaded into memory. How do I fix this?
User::chunk(1000, function ($ids) {
$calculationJob = [];
foreach ($ids as $id) {
$calculationJob[] = new UserJob();
}
$batch = Bus::batch([])
->onQueue('process-1')
->dispatch();
$batch->add($calculationJob);
});
Please or to participate in this conversation.