Cronjob fails to connect to mysql

My Mautic version is: v4.4.9
My PHP version is: PHP 7.4.33 (cli) (built: Nov 15 2022 06:03:30) ( NTS )
My Database type and version is: Server version: 5.7.42-46 Percona Server (GPL), Release 46, Revision e1995a8bb71

My problem is:

I’m running on docker. I checked and the cronjobs are running but I get this error repeatedly:

[CRON] In ConnectionFactory.php line 136:
[CRON] An exception occurred while establishing a connection to figure out your pl
[CRON] atform version.
[CRON] You can circumvent this by setting a 'server_version' configuration value
[CRON] For further information have a look at:

If I run the jobs manually they all run fine… how can I determine which is the offending one?

Also, I turned the queue on and my server froze a couple of times. I recently capped the max time to 60 seconds and it seems to be more stable.

I’m using Gmail as SMTP.


I just made a new test which was to run all of the */15 jobs at once:

sudo -u www-data php /var/www/html/bin/console mautic:broadcasts:send & sudo -u www-data php /var/www/html/bin/console mautic:messages:send & sudo -u www-data php /var/www/html/bin/console mautic:emails:send & sudo -u www-data php /var/www/html/bin/console mautic:email:fetch & sudo -u www-data php /var/www/html/bin/console mautic:social:monitoring & sudo -u www-data php /var/www/html/bin/console mautic:webhooks:process & sudo -u www-data php /var/www/html/bin/console mautic:broadcasts:send effectively simulating the cron’d execution and got to see the error first hand so I guess the problem is some sort of deadlock being triggered by the simultaneous execution of all of this cronjobs.

I’ll try to space them out in time and see if this solved the issue.

Ok so I haven’t found the root cause of the problem yet but I think I’m on the right track.

I commented out a couple of cronjobs I believe I’m not using:

#       */5 * * * *     www-data   php /var/www/html/bin/console mautic:import > /var/log/cron.pipe 2>&1
#0,15,30,45 * * * *     www-data   php /var/www/html/bin/console mautic:messages:send > /var/log/cron.pipe 2>&1
#3,18,33,48 * * * *     www-data   php /var/www/html/bin/console mautic:email:fetch > /var/log/cron.pipe 2>&1
#4,19,34,49 * * * *     www-data   php /var/www/html/bin/console mautic:social:monitoring > /var/log/cron.pipe 2>&1
#6,21,36,51 * * * *     www-data   php /var/www/html/bin/console mautic:webhooks:process > /var/log/cron.pipe 2>&1
#@reboot                www-data   [[ "$(ls -A /var/www/html/bin/cache/ip_data 2>/dev/null)" ]] || php /var/www/html/bin mautic:iplookup:download > /var/log/cron.pipe 2>&1

And my MySQL server stopped crashing.

So I guess my next step will be to enable them one by one to see which is the culprit.

Eventually I hope if I space them enough it will be alright…

Well I finally found my solution: I changed the parallel job execution to a sequential one. I noticed that if I spaced the cronjobs preventing them from running at the exact same time the MySQL server wouldn’t crash so often but then I figured it’d be easier to simply have them run one after the other instead of trying to calculate the best cronjob distribution.

So what I did was create a single job that would spawn all of the tasks (


export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

php /var/www/html/bin/console mautic:reports:scheduler > /var/log/cron.pipe 2>&1
php /var/www/html/bin/console mautic:messages:send > /var/log/cron.pipe 2>&1
php /var/www/html/bin/console mautic:emails:send > /var/log/cron.pipe 2>&1
php /var/www/html/bin/console mautic:campaigns:trigger > /var/log/cron.pipe 2>&1
php /var/www/html/bin/console mautic:email:fetch > /var/log/cron.pipe 2>&1
php /var/www/html/bin/console mautic:social:monitoring > /var/log/cron.pipe 2>&1
php /var/www/html/bin/console mautic:broadcasts:send > /var/log/cron.pipe 2>&1
php /var/www/html/bin/console mautic:webhooks:process > /var/log/cron.pipe 2>&1
php /var/www/html/bin/console mautic:segments:update > /var/log/cron.pipe 2>&1
php /var/www/html/bin/console mautic:campaigns:rebuild > /var/log/cron.pipe 2>&1

And then simplified the cron file to:


*/7 * * * * 	www-data   /var/www/html/
* 1 * * *     	www-data   php /var/www/html/bin/console mautic:maintenance:cleanup -n --days-old=365 > /var/log/cron.pipe 2>&1
0 4 15 * *     	www-data   php /var/www/html/bin/console mautic:iplookup:download > /var/log/cron.pipe 2>&1
0 5 10 * *     	www-data   php /var/www/html/bin/console mautic:unusedip:delete > /var/log/cron.pipe 2>&1

This way I can have all the jobs at a higher frequency than the original, while also keeping my MySQL server sane :stuck_out_tongue:

I’ll probably need to adjust this if the amount of emails sent grows but I think the general idea will be kept.

Also, running mysql_upgrade on the database server helped get rid of some annoying errors found in /var/log/mysql/error.log.

I hope this helps :slight_smile:

1 Like

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