Understanding PHP "Out of Memory" Error

PHP out of memory error even though memory_limit not reached

I have finally found the answer. The clue came from pcguru's answer beginning 'Since the server has only 1 GB of RAM...'.

On a hunch I looked to see whether Apache had memory limits of its own as those were likely to affect PHP's ability to allocate memory. Right at the top of httpd.conf I found this statement: RLimitMEM 204535125

This is put there by whm/cpanel. According to the following webpage whm/cpanel incorrectly calculates its value on a virtual server...
http://forums.jaguarpc.com/vps-dedicated/17341-apache-memory-limit-rlimitmem.html

The script that runs out of memory gets most of the way through, so I increased RLimitMEM to 268435456 (256 MB) and reran the script. It completed its array merge and produced the csv file for download.

ETA: After further reading about RLimitMEM and RLimitCPU I decided to remove them from httpd.conf. This allows ini_set('memory_limit','###M') to work, and I now give that particular script the extra memory it needs. I also doubled the RAM on that server.

Thank you to everyone for your help in detecting this rather thorny issue, and especially to pcguru who came up with the vital clue that got me to the solution.

Understanding php Out of memory error

I Always interpreted it like:

Fatal error: Out of memory ([currently] allocated 32016932) (tried to allocate [additional] 25152 bytes)

But good Question if there is a bulletproof explanation.

PHP understanding memory limit error

PHP tried to allocate an extra of 4194304 bytes (after your code reached the upper limit of 134217728) , but your code exhausted that too.)

134217728 was the limit which your code exceeded.

variable storage and php out of memory error

Although there are several limits, I suppose you mean the "memory_limit" value you can set with ini_set. Then the answers would actually be no.

If you set the value to the exact limit, you will be fine (if that is everything there is in your script). But the problem is when you use 1 byte more than that. So you can no longer do anything in your script. If you try to copy the value or do something with it, you will exceed the limit and it will break down. So its useless to have a string like that.

This question that was recently posted has some nice answers on it: memory-get-peak-usage-with-real-usage



Related Topics



Leave a reply



Submit