In the Mautic documentation for Cron Jobs it is pointed out that the three most important Cron Jobs should be started one after the other. However, in our opinion it is not sufficient to simply start them one after the other. The unknown is the runtime of a cron job. Especially if there are already many contacts in the Mautic database and new segments are created dynamically, it can take longer.

Solution 1 – Cron jobs are called via shell file in series

Our suggested solution: We pack the cron jobs into an executable shell file in which they are actually called one after the other. This file is then started regularly by a cron job.

  1. Create a file, e.g. with the name “cronjob.sh” in the /app directory in the Mautic installation,
  2. Write the three cronjobs into it. The syntax looks something like this:
    #!/bin/sh
    /PATHTOPHP/php /PATHTOMAUTIC/app/console mautic:segments:update
    /PATHTOPHP/php /PATHTOMAUTIC/app/console mautic:campaigns:rebuild
    /PATHTOPHP/php /PATHTOMAUTIC/app/console mautic:campaigns:trigger
  3. Customize PATHTOPHP and PATHTOMAUTIC to your own installation without forgetting
  4. Create a cron job for running cronjob.sh

Attention! Of course the Cron jobs must not be started too fast! Of course the cron jobs must not be started too fast one after the other. This is to prevent that cronjob.sh is called before the last run was finished. Start e.g. every 5 minutes – the notation for this is */5 * * * * * (more here: https://crontab.guru/)

Solution 2 – Cron Job calls Mautic commands in sequence

Meanwhile we are using a second variant, which is much faster to create. We chain all Mautic tasks via “&&;” directly when setting the cron jobs (sometimes also called “planned tasks”). This works differently from hoster to hoster, often via an administration interface.

The command that is then called looks something like this:

/PATHTOPHP/php /PATHTOMAUTIC/app/console mautic:segments:update && /PATHTOPHP/php /PATHTOMAUTIC/app/console mautic:campaigns:rebuild & /PATHTOPHP/php /PATHTOMAUTIC/app/console mautic:campaigns:trigger

In this variant the risk of parallel running cron jobs is lower, because the system “sees” the running cron job in this case. In variant 1 a shell script is simply started and the cron job is immediately completed successfully.