Solution:
If you want to reduce memory usage without editing php.ini
file, I suggest using chunk
than cursor()
.
Model::chunk(250, function ($data) {
foreach ($d as $data) {
// your code
}
});
This will take less memory but do keep in mind this may consume few seconds more for execution in contrast to cursor()
.