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...
- 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.
- 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
Where Does PHP'S Error Log Reside in Xampp
Convert Dot Syntax Like "This.That.Other" to Multi-Dimensional Array in PHP
How to Define a Class Property Value Dynamically in PHP
MySQLi::Query(): Couldn't Fetch MySQLi
How to Create a Simple 'Hello World' Module in Magento
Http Authentication Logout Via PHP
PHP Multidimensional Array Searching (Find Key by Specific Value)
Where Do We Use the Object Operator "-≫" in PHP
How to Parse a CSV File Using PHP
Getting the Names of All Files in a Directory With PHP
How to Start and End Transaction in MySQLi
Detect Language from String in PHP
MySQL Prepared Statements With a Variable Size Variable List
Remove Style Attribute from HTML Tags
Http Requests With File_Get_Contents, Getting the Response Code