Magento – Cron not working and Cron log showing Fatal error: Allowed memory size of 33554432 bytes exhausted

composercronmagento2

I have getting this error in magento 2.

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried
to allocate 28672 bytes) in

/home/www/public_html/website.com/vendor/composer/composer/src/Composer/Package/Dumper/ArrayDumper.php

on line 89

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 425984 bytes) in

/home/www/public_html/website.com/vendor/composer/composer/src/Composer/Json/JsonFile.php

on line 93

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 425984 bytes) in

/home/www/public_html/website.com/vendor/composer/composer/src/Composer/Json/JsonFile.php
on line 93

Please help me to solve this issue. thanks in advance.

Best Answer

I was facing the same issue but was able to resolve.

  • Php path which cron was using was incorrect, hence absolute path should be used.
  • Memory limit for PHP-CLI and PHP was different, so passed the params to override in CLI.
  • Example:

    
    */5 * * * * /opt/lampp/bin/php -d memory_limit=2G /opt/lampp/htdocs/magento/enterprise/bin/magento cron:run | grep -v "Ran jobs by schedule" >> /opt/lampp/htdocs/magento/enterprise/var/log/magento.cron.log
    
    */5 * * * * /opt/lampp/bin/php -d memory_limit=2G /opt/lampp/htdocs/magento/enterprise/update/cron.php >> /opt/lampp/htdocs/magento/enterprise/var/log/update.cron.log
    
    */5 * * * * /opt/lampp/bin/php -d memory_limit=2G /opt/lampp/htdocs/magento/enterprise/bin/magento setup:cron:run >> /opt/lampp/htdocs/magento/enterprise/var/log/setup.cron.log
    

/opt/lampp/bin/php : My PHP path.

/opt/lampp/htdocs/magento/enterprise/bin/magento : My Magento CLI path

memory_limit=2G : Memory limit set to 2G, you can update to it as your server limits.