Understanding php "Out of memory" error

10,547

Solution 1

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.

Solution 2

It's exactly like you understood it.

The limit is probably set at 32MB, you have already 32016932 bytes allocated and when php tried to allocate 25152 more bytes, the limit is exceeded thus the error message.

You probably can see the line where the faulty allocation happened in your logs or near the error message on your screen.

Good luck finding the culprit.

Share:
10,547
Dennis G
Author by

Dennis G

Click on CTRL+About me on your keyboard and you will be surprised!

Updated on June 30, 2022

Comments

  • Dennis G
    Dennis G about 2 years

    I can find lots of tutorials on how to overcome the out-of-memory error. The solution is: To increase the memory in the php.ini or in the .htaccess - what a surprise...

    I actually don't understand the error message:

    Fatal error: Out of memory (allocated 32016932) (tried to allocate 25152 bytes)

    "Allocated 32016932", means 32MB have been allocated as in - the PHP script is using 32MB? Tried to allocate 25152, means that another 25KB were tried to be allocated, but the script failed as the maximum (of ~ 32MB?) has been reached?

    What can I actually tell from this error message, besides that I'm "out of memory"?

  • Hannes
    Hannes over 13 years
    @MatejB you are right, but as far as I understood the Question is what you can get from that message, and unfortunately, that is all there is to get
  • Hannes
    Hannes over 13 years
    @MatejB and bad People ;) [looking in your direction] .... nah I think it is a perfectly valid Question, I myself think the error message could be a little bit more clear, especially when I started with PHP way back I remember it confusing me more then one time. The matter about how to track and deal with memory leaks is, well, a whole another matter
  • Hannes
    Hannes over 13 years
    @MatejB well, not my call, but i guess it still counts as "further reading" ?;)
  • Charlie Schliesser
    Charlie Schliesser over 12 years
    I like this answer. I would also add to it that the additional allocation is not indicative of what PHP may have needed to complete said operation, but what was being asked for over the limit at the time of the crash.
  • NoBugs
    NoBugs over 9 years
    except that it often gives vastly different allocated xxxxxxxx values, on the same server, and same setup, intermittently.
  • Hannes
    Hannes over 9 years
    @NoBugs yes, as long as the currently allocated + the additional allocated is larger then the allowed memory it will fail. Really depends on what the application is doing at any given moment. Also all kinds of things you might not be aware of can influence this value. For example the varying size of external resources loaded by php ( cache from apc, dataset from db ) ect.
  • NoBugs
    NoBugs over 9 years
    Most importantly, if the actual available memory is below the "allowed" memory, it apparently fails - accounting for vastly different "allocated xxxxxx" OOM messages.