How best to use Mautic CLI commands & cronjobs
Mautic has quiet a list of CLI commands which perform different functions. It is very important to setup cronjobs for the CLI commands according to the setup you have. There is no need to add all the CLI commands, but it is also important to know when to add or remove these. Having CLI commands running without doing anything, does not make any sense and you should remove them if not needed.
Using the command line
Every CLI commands can be executed through the command line in the following way.
$ php /home/project/public/bin/console mautic:segments:updateSetting up your own bash scripts using the CLI commands can be very useful, for example, when you want to do any maintenance work in Mautic.
Basic cronjob setup
A basic cronjob will look like this.
*/5 * * * * /user/local/bin/php /home/project/public/bin/console mautic:segments:update > /dev/null 2>&1
The path to PHP will vary from server to server.
How to time cronjobs
There is a very good article on timing cronjobs based on limits, read this here.
Mandatory cronjobs for any Mautic installation
The following 3 commands are mandatory without these, Mautic cannot operate as it should.
- mautic:segments:update
- mautic:campaigns:update
- mautic:campaigns:trigger
- mautic:messages:send - before version 5
- messenger:consume email - from version 5, this replaces the above command
The commands below are not required, however if you want 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
Going deeper into the CLI commands
Below is a detailed explanation of each CLI command and the suggested frequency.
mautic:segments:update [Required]
This cron keeps segments updated and is vital for Mautic to function.
0,15,30,45 * * * * /user/local/bin/php /home/project/public/bin/console mautic:segments:update > /dev/null 2>&1
Run this command at 15 minute intervals. If your database is very big, try running the command every 30 mins. Lower than 15 mins will cause a performance issue if your contacts increases in size.
mautic:campaigns:update [Required]
This cron keeps campaigns updated with a list of contacts and is vital for Mautic to function.
5,20,35,50 * * * * /user/local/bin/php /home/project/public/bin/console mautic:campaigns:update > /dev/null 2>&1
The timing of this command is at 15 minute intervals. This cronjob should intentionally run at a different 15 minute interval so these do not conflict.
The speed of this command can also be controlled with the following parameters:
--batch-limit=X: Limit the number of contacts to be processed (replace X with a number). By default, this script processes the contacts in a batch size of 300.
--max-contacts=Y: Limit the number of contacts to be processed (replace the value Y with a number).
mautic:campaigns:trigger [Required]
This command is important and required as it is used to execute the campaign trigger event.
10,25,40,55 * * * * /user/local/bin/php /home/project/public/bin/console mautic:campaigns:trigger > /dev/null 2>&1
The timing of this command is at 15 minute intervals. This cronjob should intentionally run at a different 15 minute interval so these do not conflict. It is recommended to keep this at 15 minute intervals.
The speed of this command can also be controlled with the following parameters:
--batch-limit=X: Limit the number of contacts to be processed (replace X with a number). By default, this script processes the contacts in a batch size of 100.
--max-contacts=Y: Limit the number of contacts to be processed (replace the value Y with a number).
mautic:messages:send [Required]
Marketing Messages are sent using this command, 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 command is optional).
10,25,40,55 * * * * /user/local/bin/php /home/project/public/bin/console mautic:messages:send > /dev/null 2>&1
The timing of this command is at 15 minute intervals. It is recommended to keep this at 15 minute intervals.
The speed of this command can also be controlled with the following parameters:
--batch-limit=X: Limit the number of contacts to be processed (replace X with a number). By default, this script processes the contacts in a batch size of 100.
--max-contacts=Y: Limit the number of contacts to be processed (replace the value Y with a number).
mautic:emails:send [Optional-before Version 5] or messenger:consume email [optional- Version 5 onwards]
If you have configured the Mautic to queue emails in a filesystem, then this command required to process the email queue.
Before Version 4.4.12
0,15,30,45 * * * * /user/local/bin/php /home/project/public/bin/console mautic:emails:send > /dev/null 2>&1
From Version 5.x.x
0,15,30,45 * * * * /user/local/bin/php /home/project/public/bin/console messenger:consume email > /dev/null 2>&1
The timing of this command is at 15 minute intervals. Do not reduce the time, else your campaigns will be delayed.
mautic:emails:fetch [Optional]
If you have configured the Mautic to handle bounce management, then this cron job is required.
0,15,30,45 * * * * /user/local/bin/php /home/project/public/bin/console mautic:email:fetch > /dev/null 2>&1
The timing of this command is at 15 minute intervals. Do not reduce the time, else this will add overhead to your server resources.
mautic:social:monitoring [Optional]
If you have configured the Mautic to do social listening, then this cron job is required.
0,30 * * * * /user/local/bin/php /home/project/public/bin/console mautic:social:monitoring > /dev/null 2>&1
The timing of this command is at 30 minute intervals. Do not reduce the time, else this will add overhead to your server resources.
mautic:webhooks:process [Optional]
If you have configured the Mautic to send webhooks, then this cron job is required.
*/30 * * * * /user/local/bin/php /home/project/public/bin/console mautic:webhooks:process > /dev/null 2>&1
The timing of this command is at 30 minute intervals.
mautic:iplookup:download [Optional]
Mautic uses MaxMind’s GeoLite2 IP database to resolve IP to location.
5 1 * * * /user/local/bin/php /home/project/public/bin/console mautic:iplookup:download > /dev/null 2>&1
It is recommended to keep this cron scheduled to be run once a day.
mautic:maintenance:cleanup [Suggested]
This command helps clean out old data from your database. You can use the --days-old=X(where X is the number of days), to clean data after X time. The command removes anonymous user data which has no real benefit until the user has been 100% identified.
10 1 * * * /user/local/bin/php /home/project/public/bin/console mautic:maintenance:cleanup --days-old=180 --no-interaction > /dev/null 2>&1
It is recommended to keep this cron scheduled to be run once a day.
mautic:import [Suggested]
This command helps to import CSV files in the background. Useful when the CSV file is fairly large.
*/5 * * * * /user/local/bin/php /home/project/public/bin/console mautic:import > /dev/null 2>&1
Run this command every 5 or 10 minutes.
mautic:reports:scheduler [Suggested]
This command is for sending scheduled reports. These are reports which you have configured for clients.
*/30 * * * * /user/local/bin/php /home/project/public/bin/console mautic:reports:scheduler > /dev/null 2>&1
Run this command every 30 minutes.
Other CLI Commands For Mautic plugins
Refer to the plugin documentation for any changes and or updates to the cron requirements below.
Mautic – Hubspot Integration
mautic:integration:fetchleads --integration=Hubspotmautic:integration:pushactivity --integration=Hubspot
Mautic – Salesforce Integration
mautic:integration:fetchleads --integration=Salesforcemautic:integration:pushactivity --integration=Salesforcemautic:integration:pushleadactivity --integration=Salesforcemautic:integration:synccontacts --integration=Salesforce
Mautic – SugarCRM / SuiteCRM Integration
mautic:integration:fetchleads --fetch-all --integration=Sugarcrm
Mautic – Pipedrive Integration
mautic:integration:pipedrive:fetchmautic:integration:pipedrive:push
Mautic Zoho CRM Integration
mautic:integration:fetchleads --integration=Zoho
Tools & Notes
If you wish to see all the Mautic CLI commands & the help information, use these commands.
mautic:list
mautic:help
To check your cronjob times use crontab guru. This will give you an idea if the cron time is correct or if it may have some issues with the syntax.
