Skip to content

Mautic cron jobs: Which ones to use?

Mautic cron jobs: Which ones to use?

There are many Mautic cron jobs you can use in your Mautic installation, but Mautic can get resource hungry over time, so you don’t really want to run them all, in fact, that would be a great mistake, you only have to add the cron jobs that you actually need in your own setup, based on your own Mautic installation and the Mautic features you’re currently using.

This is a guide to help you both, first discover and then choose the right Mautic cron jobs you want to deploy in order to have a perfectly smooth Mautic installation on your server. 

NOTE: In this post I share information about the different cron jobs you can use with Mautic, once you know which ones you want to use, If you want to learn how to actually setup the cron jobs on your server, please check this other post: Mautic Cron Jobs for dummies.

What are Mautic cron jobs?

Technically what we call Mautic cron jobs are in fact Mautic commands that are scheduled on a crontab and run by the cron daemon at the specified times or time intervals. If you want to know the technical specifics, here’s the entry for cron on Wikipedia and also cron on unixgeeks.org

Mautic has many commands that you can use to run some important tasks and processes needed for Mautic to operate, check Mautic´s health, update it’s codebase and so on…

Point being, you can use cron jobs to run these Mautic commands, but you can also run them manually by typing them in your server’s console and instantly see what a command returns, so you can test them immediately.

WARNING: Conventions used in this post:

In order to run the Mautic commands or use them in your server as Mautic cron jobs, you will first need to know the ¨path to your Mautic Installation¨. In this post I´ll be using the shortest possible path that is common to every Mautic installation, however, your real path will be longer… Whenever you see php app/console  or php /var/www/html/app/console as part of a Mautic command or used in a Mautic cron job, you have to substitute it with the actual path of the Mautic command in your own server.

If you don’t yet know the path to be used in your server, I strongly recommend you to check this post first: Mautic cron jobs for dummies & marketers.

Mandatory cron jobs to run Mautic:

The following 3 commands are mandatory and Mautic is rendered useless until you set these up:

  • mautic:segments:update
  • mautic:campaigns:update
  • mautic:campaigns:trigger

And not exactly mandatory, but you certainly don’t want to miss the following ones if you’re going to enable visitor tracking, so it’s usually used in 80% of Mautic Installations:

  • mautic:iplookup:download
  • mautic:import
  • mautic:webhooks:process
  • mautic:maintenance:cleanup –days-old=365
  • mautic:reports:scheduler

Let’s review them in more detail…

mautic:segments:update

Segments are the core of our Mautic campaigns, this command will make sure the conditions you have set for your segments are met and updated.

By default mautic:segments:update will process 300 contacts at a time, you can increase or decrease this number by using the –batch-limit parameter, here´s an example:

php /var/www/html/app/console mautic:segments:update

mautic:campaigns:update

This command updates your campaign´s settings and fetches the required contacts from your segments, depending on how much or how fast your campaigns and segments change you will want to run this command more or less often.

Mautic processes the events for 100 contacts at a time by default, you can increase the number of events processed in a batch by using the –-batch-limit modifier.

php /var/www/html/app/console mautic:campaigns:update

mautic:campaigns:trigger

This command triggers your campaigns, meaning it actually runs the campaigns. you will want to run this command as often as you need the campaigns to be actually executed.

You can increase the number of events processed by executing this task with parameter -–batch-limit, like this:

php /var/www/html/app/console mautic:campaigns:trigger

mautic:iplookup:download

Used to download/update the IP Lookup database, if you are tracking your visitor’s activity (which you should) you want to enable this Mautic Cron Job.

 php /var/www/html/app/console mautic:iplookup:download

Optional but commonly used Mautic cron jobs:

There are many Mautic cron jobs you can use in your install (see the full list at the bottom of this post). But you don’t really want to use them all. Mautic can get resource-hungry over time, so make sure you choose the cron jobs you want to use carefully and never set up any that you don’t actually need.

mautic:emails:send

There are specific cases where you will want to use the queue to send emails, if this is your case, this command will be sending the emails.
Are you using the Mautic queue to send emails? Most people will not be using Mautic’s email queue but rather sending the emails directly instead. You only have to use the queue in some specific cases, and only if you are using the queue you will need to use this Mautic cron job. You can define whether to use the queue or not at any time within the Mautic UI.

mautic:maintenance:cleanup

This command can help you clean up older data, which can be accumulating in your database and serves little to no purpose. For example, you could use it to purge anonymous contacts that never registered to your site once they reach a certain age. This Mautic cron job will remove any entries from tracking anonymous users, the default setting is 365 days. This command removes the contact entirely including IP, user notifications and visits history. Any contacts which have successfully been identified will not be affected.

See the basic command example:

php /var/www/html/app/console mautic:maintenance:cleanup --dry-run

php /var/www/html/app/console mautic:maintenance:cleanup

By running the command with the --dry-run parameter you can perform a test before actually deleting the data.

The command has another parameter where we can specify the number of days that we want to keep in our database (by default the command uses 365 days)

php /var/www/html/app/console mautic:maintenance:cleanup --days-old=90

In the example above, Mautic will erase all anonymous data older than 90 days

Important: If you use this command through a cron task, you must apply the –no-interaction parameter, otherwise the command will always request confirmation before execution.

Here’s an example of the command to use in CRON:

php /var/www/html/app/console mautic:maintenance:cleanup --days-old=90 --no-interaction

mautic:import

Cron Mautic for Importing Contacts in the Background
Mautic offers a command to perform the import of contacts in the background, excellent for those who need to import a large number of contacts but have encountered problems with a timeout.

To configure the task responsible for importing contacts in

the background, use the command:

php /var/www/html/app/console mautic:import

This command may take some time to execute depending on the number of contacts in the CSV file. In any case, you will receive a notification in the Mautic Dashboard when the import is complete.

mautic:reports:scheduler

Cron Job for Sending Scheduled Reports
If you schedule reports being sent to clients, partners, etc., you should set up a cron responsible for generating and sending the scheduled reports in the background:

php /var/www/html/app/console mautic:reports:scheduler

This Mautic feature is incredible for your customers and employees. It allows them to get an idea of how fluid your Digital Marketing is.

mautic:broadcasts:send

This command is responsible for sending the scheduled broadcast msgs. Needed for SMS, emails and other messaging… Commonly used to send SMS messages to an external SMS provider, like Twilio.
Accepts:  [–id=ID] [–channel=CHANNEL] The basic cron for this command is:

php /var/www/html/app/console mautic:broadcasts:send

Optional: This command also allows the –channel parameter where we can specify the channel we will use and -–id where we specify the id of a specific channel. For now, the –channel parameter only accepts the email value. See the complete command:

php /var/www/html/app/console mautic:broadcasts:send --channel=email --id=X

Where x is the ID of your broadcast e-mail. 

mautic:email:fetch

Needed for incoming SMTP email processing, used to fetch emails from a predefined account and folders within this email account, only required if you are using the SMTP Folders mode to receive bounces, unsubscribes, etc.

mautic:social:monitoring

Needed if Social components are used.

mautic:webhooks:process

Needed if webhooks are being used.

Mautic cron jobs for your Mautic plugins


Mautic – Hubspot Integration

mautic:integration:fetchleads --integration=Hubspot
mautic:integration:pushactivity --integration=Hubspot

Mautic – Salesforce Integration

mautic:integration:fetchleads --integration=Salesforce
mautic:integration:pushactivity --integration=Salesforce
mautic:integration:pushleadactivity --integration=Salesforce
mautic:integration:synccontacts --integration=Salesforce

Mautic – SugarCRM / SuiteCRM Integration 

mautic:integration:fetchleads --fetch-all --integration=Sugarcrm

Mautic – Pipedrive Integration

mautic:integration:pipedrive:fetch
mautic:integration:pipedrive:push

Mautic Zoho CRM Integration 

mautic:integration:fetchleads --integration=Zoho

Mautic Dynamics CRM Integration 

php /var/www/html/app/console mautic:integration:fetchleads -i Dynamics

You might also be interested in these other posts:
Mautic Self Hosted Best Practices.
Please Stop Using Bitnami and Cpanel to Install Mautic.
Download Mautic: Which Version to Use?
Mautic installation in 7 min. with PHP 7.2 on Ubuntu 18.04
Mautic cron jobs for dummies & marketers.
Install Mautic Plugin for dummies.

Full list of Mautic commands that you can use as Mautic Cron Jobs:

cache
cache:clear Clears the cache
cache:warmup Warms up an empty cache

mautic
mautic:assets:generate Combines and minifies asset files from each bundle into single production files
mautic:broadcasts:send Process contacts pending to receive a channel broadcast.
mautic:campaigns:execute Execute specific scheduled events.
mautic:campaigns:messagequeue Process sending of messages queue.
mautic:campaigns:messages Process sending of messages queue.
mautic:campaigns:rebuild Rebuild campaigns based on contact segments.
mautic:campaigns:trigger Trigger timed events for published campaigns.
mautic:campaigns:update Rebuild campaigns based on contact segments.
mautic:campaigns:validate Validate if a contact has been inactive for a decision and execute events if so.
mautic:citrix:sync Synchronizes registrant information from Citrix products
mautic:contacts:deduplicate Merge contacts based on same unique identifiers
mautic:email:fetch Fetch and process monitored email.
mautic:emails:fetch Fetch and process monitored email.
mautic:emails:send Processes SwiftMail’s mail queue
mautic:import Imports data to Mautic
mautic:install:data Installs Mautic with sample data
mautic:integration:fetchleads Fetch leads from integration.
mautic:integration:pipedrive:fetch
mautic:integration:pipedrive:push
mautic:integration:pushactivity Push lead activity to integration.
mautic:integration:pushleadactivity Push lead activity to integration.
mautic:integration:synccontacts Fetch leads from integration.
mautic:iplookup:download Fetch remote datastores for IP lookup services that leverage local lookups
mautic:maintenance:cleanup Updates the Mautic application
mautic:messages:send Process sending of messages queue.
mautic:migrations:generate Generate a blank migration class.
mautic:plugins:install Installs, updates, enable and/or disable plugins.
mautic:plugins:reload Installs, updates, enable and/or disable plugins.
mautic:plugins:update Installs, updates, enable and/or disable plugins.
mautic:queue:process Process queues
mautic:reports:scheduler Processes scheduler for report’s export
mautic:segments:check-builders Compare output of query builders for given segments
mautic:segments:rebuild Update contacts in smart segments based on new contact data.
mautic:segments:update Update contacts in smart segments based on new contact data.
mautic:social:monitoring Looks at the records of monitors and iterates through them.
mautic:theme:json-config Converts theme config to JSON from PHP
mautic:transifex:pull Fetches translations for Mautic from Transifex
mautic:transifex:push Pushes Mautic translation resources to Transifex
mautic:translation:createconfig Create config.php files for translations
mautic:translation:debug Displays translation messages informations
mautic:update:apply Updates the Mautic application
mautic:update:find Fetches updates for Mautic
mautic:webhooks:process Process queued webhook payloads


Usage:
command [options] [arguments]

Options:
-h, –help Display this help message
-q, –quiet Do not output any message
-V, –version Display this application version
–ansi Force ANSI output
–no-ansi Disable ANSI output
-n, –no-interaction Do not ask any interactive question
-s, –shell Launch the shell.
–process-isolation Launch commands from shell as a separate process.
-e, –env=ENV The Environment name. [default: “prod”]
–no-debug Switches off debug mode.
-v|vv|vvv, –verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
help: Displays help for a command
list: Lists commands

Yosu Cadilla

My name is Yosu Cadilla, a Systems Analyst and Platform Engineer for mktg.dev
I discovered Mautic in 2017 and since have specialized in:
– Running Mautic for Marketing Agencies.
– Running large Mautic instances, sometimes
with millions of contacts.
– Helping companies build and optimize their (usually Mautic) runtime infrastructure.

If you are planning on deploying Mautic for your Marketing Agency, or you have a large Mautic Instance…
Let’s have a chat! yosu.cadilla@gmail.com