Really slow Triggering of Scheduled Events

Your software
My Mautic version is: v5.1.1
My PHP version is: PHP Version 8.2.26
My Database type and version is: 10.11.6-MariaDB-0+deb12u1

Your problem
My problem is:

I upgraded Mautic and then moved it from server and I am getting a lot of problems. I do not know why exactly but I see this problem offtenly about EntityManagerClosed

What happens next is that processes get stuck and see this message:

I think the problem is related to locking of tables. I am pretty lost …

These errors are showing in the log:

[2025-01-15T00:09:19.815909+00:00] mautic.CRITICAL: Uncaught PHP Exception Doctrine\ORM\Exception\EntityManagerClosed: “The EntityManager is closed.” at /var/www/mautic/vendor/doctrine/orm/src/Exception/EntityManagerClosed.php line 11 {“exception”:“[object] (Doctrine\ORM\Exception\EntityManagerClosed(code: 0): The EntityManager is closed. at /var/www/mautic/vendor/doctrine/orm/src/Exception/EntityManagerClosed.php:11)”} {“hostname”:“mautic”,“pid”:425925}

Steps I have tried to fix the problem:

I am running and forcing php bin/console mautic:campaigns:trigger from command line.

This can happen if your commands are overlapping when you execute them.
Can you turn off the cronjobs, wait a little bit, and then run them manually?
Measure how long it takes to execute them. Is it according to your cronjobs schedule?

1 Like

Hello @Joeyk,

Thank you once again for your support. You are one of the main reasons I continue using Mautic. Your guidance, insights from ChatGPT and some posts by Yosu Cadilla (who, for reasons I am unaware of, appears to be banned from the community), has been incredibly helpful.

After following your post Mautic 5 Cronjobs and conducting several hours of research, I believe I have found the solution to my issues.

I encountered two main problems:

  1. File Permissions: After migrating my Mautic instance to a new server, I realized I had been running cron jobs as the root user. I’ve since updated this to run cron jobs under the www-data user, which resolved some issues.
  2. Blocked Tables: I noticed that some database tables were blocked, causing additional errors (because of the reason you mention above).

Thanks to your advice, I am also optimizing the cron jobs. However, I am concerned about the variability in server load. For instance, if we plan to send a large volume of emails on a specific day, this could lead to performance problems. While upgrading to a more powerful server might be an option to speed up tasks, I am unsure if it would be a cost-effective solution.

Currently they look like this:



*/15 * * * *	www-data	php  /var/www/mautic/bin/console messenger:consume email --time-limit=870

# I runned the following 3 and measured they took less than 1 minute to complete. Each of them happen every three minutes, hopefully this will avoid blocked tables. 

0,9,18,27,36,45,54 * * * *	www-data	php  /var/www/mautic/bin/console mautic:segments:update --batch-limit=2700
3,12,21,30,39,48,57 * * * *	www-data	php  /var/www/mautic/bin/console mautic:campaigns:rebuild --batch-limit=900
6,15,24,33,42,51 * * * *	www-data	php  /var/www/mautic/bin/console mautic:campaigns:trigger --campaign-limit=150

* * * * *	www-data	php  /var/www/mautic/bin/console mautic:broadcasts:send --batch=5 --limit=500

Additionally, I plan to purchase the Command Monitor plugin, which I believe will help prevent similar issues in the future. I realized something was wrong after reviewing a report showing 24,000 emails sent but 0 reads a week later. The campaign:trigger cron job had been blocked, resulting in customers receiving their Christmas message in January—a situation that could have been avoided.

I wanted to share my experience and solutions here in case it helps someone else. For Mautic to truly succeed, it needs to be both user-friendly and cost-effective.

I think that to make Mautic succeed in its vision, it has to be easy-to-use and Cost-Effective. My experience is far from easy-t-use until today… Is it possible to create a code that calculates, monitors and sets CronJobs and server usage at the same time?

This topic was automatically closed 36 hours after the last reply. New replies are no longer allowed.