How do I Fix the PHP Fatal Memory error?

Linode Staff

How do I Fix the PHP Fatal Memory error?

1 Reply

PHP Out of memory errors are one of the most common and unfortunately, hard to fix problems you will encounter when using PHP. Most of the time this is caused by PHP trying to use more memory than is allocated. Sometimes it can also be a memory leak if you are on PHP 5.2 and above.

Your first step will be to increase your memory limit. To do this you will need to change the memory limit in your php.ini file and then reload your web server. If you google this issue you will see many people suggest you use

       ini_set('memory_limit', '-1');

I would not suggest setting the memory limit to -1 for the long term, it is useful to see if this is the actual cause of the issue, but if you get a runaway process it will continue to use more and more memory until your Linode is either overloaded or freezes. You are better off giving it a specific limit like

       ini_set('memory_limit', '1024M');

If by increasing the memory limit you have gotten rid of the error and your code now works, Congrats!, if not you can try increasing it further but you will most likely have to dive deeper into debugging the issue. I have provided several links below to more information on this subject.

Stackoverflow #1

Stackoverflow #2

Debug guide

I hope this was helpful.

Regards,
Alex
Linode Support Team

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct