In one of application that I maintenance (PHP based) I got the E_ERROR which is connected to the memory - "Allowed memory size of 134217728 bytes exhausted...".
I am familiar with temporary solutions like setting up higher amount of memory for the script etc. but it is just temporary solution and here I need to solve it from the roots.
I have checked amount of memory which is used after each part of code in my script by simply writing it to the log file like:
addMsg('1 - Memory Usage: ' . (memory_get_usage()/1048576) . ' MB \n');
By this method I have found out that only one simple line of code increase drastically memory usage and it is: session_start()
function, which then causes this error.
Interesting thing is that this error does not occur every time scripts loads. It occurs from time to time (based on high traffic on that app, it occurs every few minutes). Also, I have found out about this error from New Relic which I use for monitoring and from logs. Although, I have never experienced myself.
Does anybody have any theoretical idea how this simple function can cause such memory usage that it cause E_ERROR?
Also, all of my errors look something like this:
Allowed memory size of 134217728 bytes exhausted (tried to allocate 10556354 bytes) in Unknown on line 0
Allowed memory size of 134217728 bytes exhausted (tried to allocate 10399243 bytes) in Unknown on line 0
Allowed memory size of 134217728 bytes exhausted (tried to allocate 8112988 bytes) in Unknown on line 0
From my point of view, it seems that script wanted to allocate less space than it was allowed and even that, error occurred. Am I right or something else is going on?