2.20.8. Fatal error: Allowed memory size
Mistake "Fatal error: Allowed memory size" means that the script exceeded the PHP parameter value during its work memory_limit current tariff plan.
Fatal error: Allowed memory size of X bytes exhausted (tried to allocate Y bytes) in /home/example/example.com/www/path/to/script.php on line Z
NS— available memory size, specified by the PHP parameter memory_limit, in bytes.
Y— the amount of memory that the script tried to use in excess of the available amount at the time of the error, in bytes.
/home/example/example.com/www/path/to/script.php— full path to the script, during the execution of which an error occurred.
Z- line number in the script where the error occurred.
Attention!Sum of values
Yis not required value memory_limit, insofar as
Yshows the amount of memory that was not enough at the time of the abnormal termination of the script, and in the case of further work, the script may require a much larger amount of memory.
Most often, the error occurs in the following situations:
- The most common situation in which a script runs out of all available memory is working with images. PNG and JPG formats compress the image, but PHP loads it into memory pixel by pixel to work with it, as if it were saved in BMP format. This results in the script running out of memory to process the image. To avoid an error, you should reduce the size of images before uploading them to the site and do not rely on the fact that PHP itself will change the format of images in high resolution.
- Executing database queries that return too large amounts of information that do not fit into available memory.
- Processing large XML files.
- Running resource-demanding or just unoptimized scripts and modules.
The solution to the problem might be:
- Changing the value of memory_limit in PHP settingsif the value is not set to the maximum available at the current tariff.
- If the site uses outdated scripts, be sure to check if the set for the site matches PHP version recommended by the site developer. If not, change it to the one you need and check the site in about 10-15 minutes.
- Reducing the size of the files processed by the script, analyzing the work and optimizing the script itself or the module in order to reduce its memory consumption.
- Tariff change to another, with a greater value memory_limit.
Attention!When changing the tariff plan, it should be borne in mind that this will only help in cases where the memory requirements are imposed by the CMS developers, as well as in some cases of processing large files. In the case of a resource-demanding script (usually self-written), you need to fix the script itself.
Note for WordPress: if the size of the actually allocated memory (value
NS) less than PHP value memory_limit of the used tariff plan, it is necessary to file wp-config.php add line:
xxx — meaning memory_limit tariff plan.