Reputation: 8950
On my server I have the following error:
Allowed memory size of 268435456 bytes exhausted
This happens in a loop (a foreach one) and when I'm checking the memory usage in the loop with
memory_get_peak_usage();
I obtain 7254128
which is far from the 268435456
exhausted!
I checked at multiple places and the memory usage is not increasing wildly so I really don't know where the problem is!
The same script is working just fine on my local computer where I setted the memory limit to only 16M
in my php.ini
file
Here is the code causing the problem, but i think it won't be really usefull, it's from a plugin of question2answer open source plateform:
foreach ($badges as $slug => $info) {
$badge_name=qa_badge_name($slug);
if(!qa_opt('badge_'.$slug.'_name'))
qa_opt('badge_'.$slug.'_name',$badge_name);
$name = qa_opt('badge_'.$slug.'_name');
}
Upvotes: 3
Views: 550
Reputation: 25711
I strongly suspect your problem will be due to a 'mis-feature' in the standard MySQL connector library. When a row that contains a 'long blob' or 'long text' field is fetched from the database. Instead of allocating the exact size required for the data, the MySQL library is trying to allocate the largest size that could be possibly be needed to store the row. i.e. 4 gigabytes of memory.
The easiest way to fix this is to switch to using the MySQL ND connector which doesn't have this 'feature'
PHP massive memory usage for SQL query
Allowed memory size of 67108864 bytes exhausted
I'm checking the memory usage in the loop with memory_get_peak_usage(); I obtain 7254128 which is far from the 268435456 exhausted!
That is correct. The memory allocation is failing so peak memory usage never shows the huge allocation as in use.
btw You should have been able to trace the error message to the exact line of code that is generating the failed memory allocation error. If it's not originating from an SQL fetch, then the answer may be wrong.
Upvotes: 1