Ad

How to Setup and Optimise Mautic Cron Jobs for Better Performance?

Posted mautic

Introduction

In case of any cloud software/services, you don’t have to worry about how the software is running at the background and how to optimise it for scale. But, when it comes to an installed version of any software, you have to take care of every aspect of a software. 

Mautic is an Open Source Software, which needs to be installed on your machine. This means you need to take care of every aspect of its operation, be it be the installation, setting up the cron or connecting with other services to deliver emails, SMS or any other notification. In this tutorial, you will learn what is cron jobs, how to set up the same for Mautic and how to optimise it to achieve better scale.

What is Cron Jobs?

Skip to the next section, if you’re not new to cron.
In simple language, cron jobs (also known as Task Schedulers in windows) is a light-weight software which runs at the background and has the capability schedule a task that needs to be executed sometime in the future. You can do both one-time schedulings of the task as well, you can schedule tasks which need to be executed periodically. 

For example, you want a script to be executed every morning at 6 am. So, this task can be added in the cron job with the following syntax:

00 06 * * * dibya /net/bin/extract.sh 

Let’s understand what this cron job means:

# .---------------- Minute (0 - 59)
# |  .------------- Hour (0 - 23)
# |  |  .---------- Day of the month (1 - 31)
# |  |  |  .------- Month (1 - 12) or jan
# |  |  |  |  .---- Day of week (0 - 6) (Sunday=0)
# |  |  |  |  |
# 00 06 *  *  * <UserName>  <Command that need to be executed>

If you’re new to cron, then you must refer the Apache documentation on cron jobs.

Mautic Cron Jobs

There are a lot of activities you do from your Mautic web app like the creation of segment, broadcasting of messages, setting rules to capture social responses and so one. Some of these activities require the system to keep updating the data, generate reports or start sending emails at some scheduled time. For achieving all these, Mautic has some programs called “Mautic Cron Jobs” which need to be executed in the background at set frequencies.

In the following section, you’ll learn what are the different types of cron jobs in Mautic, and why they are required.

List of Mautic cron jobs:

mautic:segments:update [Required]

This cron is important and required because this is used to keep the segments always updated.

0,15,30,45 * * * * <UserName> php /path/to/mautic/app/console mautic:segments:update

It is recommended to keep this cron scheduled to be run every 15 mins. If the size of your database is very big, you can choose to schedule this for every 30 mins. But, don’t reduce it beyond 15 mins, because that can have performance impact as the size of your contact list increases.

mautic:campaigns:update [Required]

This cron is important and required because this is used to keep the campaigns updated with the list of contacts who are eligible to be a part of the campaign.

5,20,35,50 * * * * <UserName> php /path/to/mautic/app/console mautic:campaigns:update

You might have observed that the timing of this cron is 5,20,35,50, unlike the previous cron where the time was 0,15,30,45. This has been intentionally done in order to ensure the timings distributed and not two crons are running at the same time.

Like the previous cron, here are also two advanced parameters to control the speed at which this cron processes the data:

--batch-limit=X: You can limit the number of contacts to be processed in a batch by just replacing the value X with a number. By default, this script processes the contacts in a batch size of 300.

--max-contacts=Y: You can also limit the number of contacts to be processed in an instance by using this parameter. Just replace the value Y with a number.

mautic:campaigns:trigger [Required]

This cron is important and required because this is used to execute the campaign trigger event.

10,25,40,55 * * * * <UserName> php /path/to/mautic/app/console mautic:campaigns:trigger

It is recommended to keep this cron scheduled to be run every 15 mins like the segment cron. Don’t reduce the time further, else your campaigns will get delayed.

Like the previous cron, here are also two advanced parameters to control the speed at which this cron processes the data:

--batch-limit=X: You can limit the number of contacts to be processed in a batch by just replacing the value X with a number. By default, this script processes the contacts in a batch size of 100.

--max-contacts=Y: You can also limit the number of contacts to be processed in an instance by using this parameter. Just replace the value Y with a number.

mautic:messages:send [Required]

There are a set of messages that are marked as Marketing Messages, these are by default inserted into a message queue only if the frequency rules are setup. To process these queues, you need to add the below cron job, else this cron is optional:

10,25,40,55 * * * * <UserName> php /path/to/mautic/app/console mautic:messages:send

It is recommended to keep this cron scheduled to be run every 15 mins like the segment cron. Don’t reduce the time further, else your campaigns will get delayed. Like the previous cron, here are also two advanced parameters to control the speed at which this cron processes the data:

--batch-limit=X: You can limit the number of contacts to be processed in a batch by just replacing the value X with a number. By default, this script processes the contacts in a batch size of 100.

--max-contacts=Y: You can also limit the number of contacts to be processed in an instance by using this parameter. Just replace the value Y with a number.

mautic:emails:send [Optional]

If you have configured the Mautic to queue emails in a filesystem, then the below cron is required to process the email queue:

0,15,30,45 * * * * <UserName> php /path/to/mautic/app/console mautic:emails:send

It is recommended to keep this cron scheduled to be run every 15 mins. Don’t reduce the time further, else your campaigns will get delayed.

mautic:emails:fetch [Optional]

If you have configured the Mautic to do the bounce management, then this cron job is required:

0,15,30,45 * * * * <UserName> php /path/to/mautic/app/console mautic:email:fetch

It is recommended to keep this cron scheduled to be run every 30 mins. Don’t reduce the time further, else it will be an overhead to resources.

mautic:social:monitoring [Optional]

If you have configured the Mautic to do social listening, then this cron job is required:

0,15,30,45 * * * * <UserName> php /path/to/mautic/app/console mautic:social:monitoring

It is recommended to keep this cron scheduled to be run every 30 mins. Don’t reduce the time further, else it will be an overhead to resources.

mautic:webhooks:process [Optional]

If you have configured the Mautic to send webhooks, then this cron job is required to send the webhooks data to the external URL:

* */30 * * * <UserName> php /path/to/mautic/app/console mautic:webhooks:process

It is recommended to keep this cron scheduled to be run every 30 mins.

mautic:iplookup:download [Optional]

By default Mautic internally used MaxMind’s GeoLite2 IP database to resolve IP to location. MaxMind keeps updating its database once every month. In order to get the local copy of the data synced, you need to add the below cron job:

* * * * 2 <UserName> php /path/to/mautic/app/console mautic:iplookup:download

It is recommended to keep this cron scheduled to be run every 10 mins.

Hope, this tutorial helped you in setting you the Mautic cron. In case you discovered something which is not covered as a part of this tutorial, then please feel free to share those below in comments.