Menu

1 / 2

PHP Allowed Memory Size Exhausted: Causes and Fixes

DEV Community: php·devTalk·8 days ago
#xlrrqQOL
#devto#dev#memory#size#limit
Reading 0:00
15s threshold

The error looks like this, and it always stops the script on the spot:

PHP Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 33554440 bytes) in /var/www/app/report.php on line 3

Enter fullscreen mode

Exit fullscreen mode

The quick fix is to raise memory_limit . The better fix is to find out why the script needs that much memory, because in most cases it is holding something it could have processed piece by piece. Here is how to read the message, raise the limit properly, and cut the memory use itself.

Reading the message

Allowed memory size of 33554432 bytes is your memory_limit in bytes. Divide by 1,048,576: this one is 32 MB.

tried to allocate 33554440 bytes is the single allocation that failed, not the total used. A big number here usually means one large array or string being created or grown. PHP arrays resize by doubling, so a loop that appends to an array fails at a request about the size of the array so far.

in ...…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.