Since I posted my Mautic 5 email sending videos, I’m getting a LOT of questions about cronjobs. I have been doing a lot of tests, and still not 100% happy with my setup. But I anyway wanted to share how I set up my cronjobs to get you started.
Cronjobs are the heart of your Mautic. No, really, the cronjobs will determine how fast the segments are being rebuilt, how fast the campaigns are pumping the contacts through the processes, and how fast your emails are being sent out.
Before releasing a longer article on slow/fast/superfast email sending setup, I just wanted to give you a generic Mautic Cron Job setup that works well if you are starting out.
I use a bash file where I have almost all my cronjobs included. I usually store it in /usr/local/bin and call it mauticcrons.sh
You can create it with the following commands:
cd /usr/local/bin
nano mauticcrons.sh
My generic content is as follows:
#!/bin/bash
MAUTICCONSOLE="/var/www/html/mautic/bin/console"
php $MAUTICCONSOLE mautic:campaigns:rebuild --batch-limit=300
php $MAUTICCONSOLE mautic:segment:update --batch-limit=900
php $MAUTICCONSOLE mautic:campaigns:trigger --campaign-limit=50
php $MAUTICCONSOLE mautic:import --limit=5000
php $MAUTICCONSOLE mautic:webhooks:process
php $MAUTICCONSOLE mautic:reports:scheduler
php $MAUTICCONSOLE mautic:broadcast:send --batch=5 --limit=500
I usually ran this script every minute, so my Mautic is fast paced, and don’t have to wait too long for the next segment update. So I call this script in my crontab. Please adjust the MAUTICCONSOLE variable if needed.
You can call the script from the crontab of the www-data user, if that is the one running your webserver:
sudo crontab -e -u www-data
Now call the script every minute:
* * * * * /bin/bash /usr/local/bin/mauticcrons.sh
This works if you don’t use queue for email sending. If you do, then all of your messages will be added to the database instead of being sent out. You can push them towards your SMTP provider by consuming the messages.
Without going into all the optimization (tutorial coming soon), you will need another command to do so. This command is a bit different then the ones above, cause it won’t stop after it’s successfully executed, but it will wait for further jobs until told otherwise. Such a good worker!
We could run this worker once and just leave it, but I suggest to tell it to work for 14 and a half minutes and, take a 30 second break and then start again.
You can do this by adding this cronjob to your crontab right next to your bash script, so your crontab would need an additional line:
* * * * * /bin/bash /usr/local/bin/mauticcrons.sh
*/15 * * * * /var/www/html/mautic/bin/console messenger:consume email --time-limit=870
And we are done. Enjoy!