blog
Table of Content
  • Cause of the Allowed Memory Size Bytes Exhausted Error
  • Running a Large Dataset
  • Poor Code Optimisation
  • Using Too Many Extensions
  • Cache or Indexing Issues
  • Solution to Allowed Memory Size of Bytes Exhausted Error
  • Method 1: Edit the php.ini File
  • Method 2: Use the Command Line
  • Method 3: Edit the index.php in Magento Root
  • Final Thoughts on Allowed Memory Size Exhausted php

Every day you read articles or hear stories from friends and family about a person running a successful online store. Indeed, running an eCommerce store can be a financially rewarding experience. Nevertheless, the journey is not smooth, and you are bound to run into challenges. The challenges range from late product deliveries to technical problems.

Speaking of challenges, if you are running a store in Magento 2, you are bound to encounter the PHP Fatal Error “Allowed Memory Size”. The error looks something like “allowed memory size of xxxx size exhausted” or “allowed memory size of 536870912 bytes exhausted”. This is nothing to worry about since there’s a quick and reliable fix for it.

This article discusses everything there is to know about this error, including its causes and the most appropriate fix.

Check Out Our Must-Have Extensions for Any eCommerce Store:

Cause of the Allowed Memory Size Bytes Exhausted Error

The cause of the error “allowed memory size of bytes exhausted” is obvious i.e. it’s related to shortage of memory. The error occurs if you try to use more RAM resources than what you have specified in the php.ini file through “memory_limit”.

Running a Large Dataset

It can occur when you are running an operation using a large dataset. While Magento is a highly powerful platform, it consumes significant server resources. Therefore, memory issues are quite common. For example, when simultaneously updating thousands of product descriptions or importing/exporting a large number of products into the database, you may see ‘allowed memory size of bytes exhausted’ error.

Poor Code Optimisation

Poorly written code can also result in high memory consumption. Therefore, always choose a reliable Magento development company when you require custom development work. They have the experience and skills necessary to take on any project, regardless of its complexity.

Using Too Many Extensions

Secondly, Magento 2 is a highly customisable platform. With extensions and custom Magento development, you can tailor each aspect to your requirements. However, using a large number of extensions and customisations can cause you to consume large amounts of memory. It is quite common to experience the allowed memory size of bytes exhausted in such a situation.

Cache or Indexing Issues

Solution to Allowed Memory Size of Bytes Exhausted Error

Remember, out of memory errors are quite common but equally easy to fix.

Method 1: Edit the php.ini File

All you need to do is increase the memory limit in the php.ini file and this will resolve the ‘allowed memory size of bytes exhausted’ error. It is the default configuration file that is used to control upload sizes, file timeouts and resource limits. This is what you have to do to resolve the error.

  • Locate php.ini file. This will usually be etc/php.ini.
  • Find the parameter memory_limt =128M
  • Increase the limit to 2G (2048 MB)

Method 2: Use the Command Line

You can also increase the memory limit using the following commands.

php -d memory_limit=1G bin/magento setup:di:compile

php -d memory_limit=1G bin/magento setup:static-content:deploy

You can change 1G to whatever limit you want. This will surely resolve the error allowed memory size of bytes exhausted in Magento 2.

Method 3: Edit the index.php in Magento Root

Open the index.php file and then add:

ini_set('memory_limit', '2G');

You can change 2G to 4G or any other number as per your requirements.

Final Thoughts on Allowed Memory Size Exhausted php

While the above solutions can resolve the error, we recommend addressing the underlying issues. You must optimise your code and limit the use of extensions. In most cases, merchants use overlapping extensions. As a leading Magento development company, we can conduct a comprehensive audit of your store. Contact us in case you require help in this regard or have any questions related to this article.

Read More Magento Blogs:

This blog was created with FME's SEO-friendly blog