Allowed memory size in Magento

Allowed memory size in Magento

August 16, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Allowed memory size in Magento

Solving Memory Exhaustion Issues in Magento

Understanding the Problem

When working with Magento, you may encounter memory exhaustion errors like the ones described by the user above:

Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 88 bytes) in /home/staging/public/kralengroothandel/app/code/local/Zend/Db/Statement/Pdo.php on line 297

or

Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 83 bytes) in /home/staging/public/kralengroothandel/lib/Varien/Simplexml/Element.php on line 196

These errors occur due to Magento’s Zend_Db and Varien libraries trying to handle unusually large datasets, leading to memory exhaustion.

Identifying the Root Cause

The issues seem to originate from the Zend_Db_Statement_Pdo class:

public function _execute(array $params = null)
{
    try {
        if ($params !== null) {
            return $this->stmt->execute($params);
        } else {
            return $this->stmt->execute();
        }
</code></pre>

And the Varien_Simplexml_Element class:

public function fetchAll($style = null, $col = null)
{
    if ($style === null) {
        $style = $this->_fetchMode;
    }
    try {

        if ($style == PDO::FETCH_COLUMN) {

            if ($col === null) {
                $col = 0;
            }
            return $this->stmt->fetchAll($style, $col);
        } else {
            return $this->stmt->fetchAll($style);
        }
</code></pre>

These classes are part of Magento’s core functionality and handle database queries. The user’s attempt to set the memory limit directly in the Pdo.php file was unsuccessful because the Zend_Db library already has an internal memory limit.

Potential Reasons for the Issue

The user mentioned they have installed the OneStepCheckout extension, which could potentially be causing a performance issue when combined with their current setup. Additionally, their use of Nginx and PHP-FPM might indicate that the server configuration could be contributing to the problem.

Solving the Memory Exhaustion Problem

1. Increasing the Global Memory Limit

The first step is to increase the global memory limit in your php.ini file:

memory_limit = 2048M

Restart your webserver after making this change.

2. Optimizing Your Database Queries

Ensure that your database queries are optimized and not pulling unnecessary data into memory. You can use tools like Magento 2 Performance Tool to identify slow queries.

3. Modifying the PHP-FPM Configuration

The user has a reasonable PHP-FPM configuration, but let’s ensure it aligns with best practices:

pm = dynamic
pm.max_children = 2
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 2

request_terminate_timeout = 0
request_slowlog_timeout = 0

chdir = /

php_admin_value[memory_limit] = 2048M
php_admin_value[post_max_size] = 128M
php_admin_value[post_max_vars] = 64000
php_admin_value[max_execution_time] = 3600
php_admin_value[realpath_cache_size] = 16m

We’ve increased the memory limit to 2048M and doubled the pm.max_children value. This allows PHP-FPM to handle more concurrent requests efficiently.

4. Disabling Unnecessary Extensions

If you have any unnecessary extensions enabled in your php.ini file, consider disabling them to reduce overall memory usage.

Conclusion

Solving memory exhaustion issues in Magento often requires a combination of server configuration adjustments and application-level optimizations. Increasing the global memory limit is a straightforward solution when dealing with memory-related errors.

However, it’s crucial to understand that setting an artificially high memory limit without addressing the underlying cause can lead to other performance issues or even crashes if your server runs out of available RAM. Therefore, always attempt to optimize your database queries and disable unnecessary extensions before resorting to increasing the memory limit.

Remember to keep your Magento store up-to-date with the latest patches and security updates provided by Laravel Company. Regular maintenance and performance tuning will help prevent such issues from arising in the future.

Database Errors

Our network