Fatal Error: Allowed Memory Size of 134217728 Bytes Exhausted (Codeigniter + Xml-Rpc)

php - Fatal error: Allowed memory size of 134217728 bytes exhausted

There is an infinite loop because you forgot to increment $i.

$i = 0;
while ($i < $rows) {
array_push($columnNames, toCamelCase($firstRowNames[$i]));
}

better:

$i = 0;
while ($i < $rows) {
array_push($columnNames, toCamelCase($firstRowNames[$i]));
++$i;
}

Memory available bigger than tried error in PHP

The error message tells you that a limit of 134217728 bytes (128 MB) was defined. This has already been used by your script, but it requested more. Allocating the next bytes (in your example: 20480) failed, that's why the script died.


To resolve this, you could either check why your script needs that memory (reducing the memory footprint can always be a good idea), or otherwise set a higher memory limit

Why is CodeIgniter exhausing allowed memory size?

Found the answer:

$this->load->database(); // init db connection, already in code
$this->db->save_queries = false; // ADD THIS LINE TO SOLVE ISSUE

This is a lovely undocumented setting in CodeIgniter. CI apparently saves queries by default, even a certain amount of data is saved relative to insert / update queries. With the massive amount of inserts run during this import process, this memory leak became very consequential. Setting CI to not save queries solved the problem.

What threw me off was that memory_get_peak_usage() was reporting the memory usage increasing before the insert query was run, not during it (PHP bug?).

As a final reality check, I removed all the other optimization recommendations (unset, clearstatcache, etc) and verified that they had no positive impact on the memory issue.



Related Topics



Leave a reply



Submit