Diagnosing Memory Leaks - Allowed Memory Size of # Bytes Exhausted

Laravel - after simple DB query memory leak / Allowed memory size of .. bytes exhausted

This is a Homestead issue: https://github.com/laravel/homestead/issues/825

Update Homestead or use php7.1 artisan ....

How to avoid Allowed memory size of ... bytes exhausted when inserting multiple large queries with Illuminate?

Other developers have found disabling Query logs and unsetting/disabling the event dispatcher on the DB connection helpful. I.e:

DB::disableQueryLog();

$dispatcher = DB::connection()->getEventDispatcher();
DB::connection()->unsetEventDispatcher();

for (many times) {
MyModel::insert($large_array);
}

DB::enableQueryLog();
DB::connection()->setEventDispatcher($dispatcher);

Resource: Query builder memory leak on large insert #27539

PHP Allowed memory size of X bytes exhausted

You can reduce memory usage two other ways without increasing the memory limit...

  1. Consider setting $mpdf->simpleTables = true; if you do not need complex table borders, or $mpdf->packTableData = true; if you do not mind the extra processing time.
  2. packTableData – Use binary packing of table data to reduce memory usage

Both of which will increase processing time in order to save memory usage.



Related Topics



Leave a reply



Submit