How to fix Magento cron job crashes with “Allowed memory size exhausted at […] Pdo.php on line 290”?

Symptoms

The exact error when executing the cron job manually (/usr/bin/php -f /var/www/vhosts/example.com/httpdocs/cron.php) was:

PHP Fatal error:  Allowed memory size of 536870912 bytes exhausted (tried to allocate 7 bytes) in /var/www/vhosts/onlinediscountmarkt.de/httpdocs/lib/Zend/Db/Statement/Pdo.php on line 290

Solution

This error can happen if Magento's cron_schedule table has too many records, coming from the log entries of past cron runs. So, delete all the entries, directly in the database with TRUNCATE TABLE cron_schedule; or using phpMyAdmin or similar.

Now, when calling the cron job again from the command line, it finishes normally, without a crash.

Prevention

It seems that the table could become that full because in "System -> Configuration -> System -> Cron", "History cleanup every" was set to "1440", thinking this was to be set in minutes. But instead, it seems it's set in days. The same for "Success history lifetime" and "Failure history lifetime" there. So better set all three to some meaningful value like "30".

Discussion

This "Allowed memory size exhausted" error also persisted after installing the AOE Scheduler module and removing all scheduled cron tasks, then calling the cron job manually. This hinted to the fact that this error is unrelated to any single of Magento's various cron tasks (so also independent of installed contrib modules), and instead happens in Magento core. (This is Magento 1.5.0.1 by the way.)

Also, from searching the error message on the Internet, it appears that the "Allowed memory size exhausted" problem at this specific code location is a rather generic error that else happens for example when processing too many product records at once (see for example here or here).

This had me look at Magento's cron_schedule table, in this case it had 673498 entries according to AOE scheduler (in the database, even 830,881 rows). These were too many records for Pdo.php to process within the memory limits: in line with other reports of the "Allowed memory size exhaused" error in Pdo.php line 290, the error was here caused by too many records in this cron_schedule table.


Posted

in

,

by

Tags:

Comments

7 responses to “How to fix Magento cron job crashes with “Allowed memory size exhausted at […] Pdo.php on line 290”?”

  1. jack

    so you mean to say if i will truncate the cron_schedule table it won’t appear.?

    i just tried solution you suggested but it is not working,

    actually i have problem with layered navigation. it is not appearing in category page. i had remove the layered navigation code before . i just added it and i got this error.

    i am not able to add layered navigation again. do you you know to rectify this issue.

    i google it and most of people are saying increase memory_limit and execution time and so.. but i don’t see it working

    how to fix it?

  2. The Pdo.php file seems to be some generic code that deals with database records, and will spit out the "memory exhausted on line 290" error whenever it has to process too many records at once. This can be cron log records like here, product records in other cases, and so on. So it's up to you to find out which table / kind of records it could be in your case with layered navigation. Of course after increasing memory_limit to some reasonably high value like 512 megabytes first … Good luck!

  3. JOHN RYON

    DID ANYONE know how to fix this issues, my website is fine and admin access is fine, when I go to catalog dropdown press category, the window show this following Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 82 bytes) in /home/concon/public_html/lib/Zend/Db/Statement/Pdo.php on line 290

    thanks you

    best regards,
    john ryon

  4. TonkBerlin

    When I made sure the cronjob was able to run -> the error disappears.
    Greets

  5. Alex

    Thanks for sharing such a great article, really i had been looking for help in creating cron job, i found one post here: https://www.cloudways.com/blog/setup-magento-cron-job/ , i got help from both posts, helped me a lot and i have created the cron job for email.

  6. suthan alley

    Thank you for this tutorial regarding Magento cron job. I have gone through several tutorial and I find your tutorial one of the best to solve my issue while implementing the code. Also I have seen other tutorials including https://magenticians.com/how-to-setup-cron-job-in-magento/

  7. I appreciate you sharing the great post! The Magento crontab is the configuration used to run Magento cron jobs. Magento uses cron tasks that can run with different configurations.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.