PHP Allowed Memory Size Exchausted Fatal Error

»»»PHP Allowed Memory Size Exchausted Fatal Error
A functional PHP script returns the following error either on the web page or in Apache error log file when it exchausted and used up the default memory requirement of 8 MB memory allocation:

PHP Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate … bytes) in …

The error normally occurs when PHP tries to process a big database records or when importing or exporting. To solve the error, there are two resolutions. One is to change and increase the memory limit of the particular PHP script by adding or including an additional line at the top of the script:

ini_set(“memory_limit”,”16M”);

You can assign the memory limit to any amount you like by changing the 16M to other number, such as 12M or 24M. 16M will set the memory limit to 16 megabytes. If this doesn’t work and the PHP error still appearing, increase the memory limit until the PHP scripts running perfectly or the limit of your system hardware.

To change the memory allocation limit permanently for all PHP scripts running on the server, modify the PHP.INI configuration file of the server (location depending on your OS and installation method). Search for memory_limit after opening the file in an editor. If the memory_limit doesn’t exist, add the following line. If it’s there, modify the value of the memory_limit:

memory_limit = 12M

The 12M sets the limit to 12 megabytes (12582912 bytes). Change to the value you desirable.

An alternative way is to modify your PHP scripts that generate the error for more efficiency and better data handling.

By |2016-12-09T08:42:57+00:00December 9th, 2016|Categories: Web Servers|Tags: |17 Comments

About the Author:

LK is a technology writer for Tech Journey with background of system and network administrator. He has be documenting his experiences in digital and technology world for over 15 years.Connect with LK through Tech Journey on Facebook, Twitter or Google+.