How to Prevent Allowed memory size Exhausted in PHP

If you are working on PHP, then definitely you are familiar with Fatal Error Allowed memory size exhausted. This error occurs when your PHP script exceeds the default memory allocated for execution. Due to which your scripts stop working and shows the error message that allowed memory size exhausted.

To know the default memory allocated for execution, you can check the memory limit in your php.ini file.

php.ini file path on Ubuntu.

open your php.ini file


and search for memory_limit. Check how much memory is allocated, you can increase this memory limit to get rid of this error message.

Subscribe Our Tutorials

Get Latest Updates on Facebook

Basic Vi/Vim Commands

How to avoid PHP script running out of memory

In my case, I have allocated 128 MB. You can allocate as per your need.

PHP Video Tutorials.

NOTE: If you make any changes in php.ini file, you need to restart the apache webserver.

If you don’t want to edit php.ini file you can allocate memory limit in your php file as well.

Fatal error: Allowed memory size Exhausted Error in WordPress

There are numerous cases where people, complain them that when they try to install and activate new plugin the error comes.

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 7680 bytes)

The simple solution of this problem is Open your wp-config.php file and include the following line

In case your host does not allow increasing memory limit in that way. Then it will not work. Contact your host they might increase memory limit through php.ini file.

About WebRewrite

I am technology lover who loves to keep updated with latest technology. My interest field is Web Development.
Tagged , , . Bookmark the permalink.