Using Cron to trigger php jobs

CiviCRMCron allows you to trigger php jobs periodically. In CiviCRM this includes triggering mailouts for example. This article describes setting up Cron using the cPanel cron jobs tool. There are two methods described here, the URL method and the PHP-CLI method. I've found the PHP-CLI method to be more reliable with recent versions of Joomla and CiviCRM.


URL method

Start by accessing the root directory with your preferred file browser.

  1. In Joomla, browse to /administrator/components/com_civicrm/
  2. Open the civicrm.settings.php file for editing.
  3. Find the following line (maybe line 284):
define( 'CIVICRM_SITE_KEY', '26ef1a41b2f4a1246b58b345e4b28bab');

This is your automatically created site key, that you'll need in the next step.

 

Cron Job

Log on to your web hosts cPanel.

  1. Click the Cron Jobs icon.
    1. If it's not available you'll need to contact your web host.
  2. In the Add a New Cron Job section, configure the schedule (e.g. */15 * * * *)
  3. In the Command: box, enter the following command and click the Add New Cron Job button.
curl --silent --compressed 'https://yoursite.com/administrator/components/com_civicrm/civicrm/bin/cron.php?name=username&pass=password&key=26ef1a41b2f4a1246b58b345e4b28bab'  > /dev/null 2>&1

The key value is the site key copied from the previous step. Name is your Joomla super admin username, and pass is the user's password. The --silent option stops the progress bar appearing, and the --compressed option allows curl to request a compressed response, neither are necessary for the cron job to work and the compressed option may not be supported on your host. The > /dev/null 2>&1 option sends the output to a null file, preventing an email being sent, and was required by my host, but might not be needed for your host.

 

PHP-CLI method

For the PHP-CLI method you don't need the site key, and you can simply set up your cron job command as follows:

/path/to/php /path/to/civicrm/bin/cli.php -s site -u user -p password -e Job -a execute

The -s site parameter is only needed for Drupal sites and can be removed. The -u user parameter refers to a super user on your Joomla site with the associated password. You will need to know the path to your php install. The following is an example that worked for me, using Siteground hosting:

/usr/local/php56/bin/php-cli /root/of/site/administrator/components/com_civicrm/civicrm/bin/cli.php -u steven -p myPassword123 -e Job -a execute

 

Managing CiviCRM jobs

Now that your cron job has been created, you can manage various CiviCRM jobs.

  1. Go to Administer > System Settings > Schedule Jobs.

At your discretion, you might want to enable the following jobs, by clicking Edit and then selecting the Is this Scheduled Job active?

  1. Clean-up temp data and files (Hourly)
  2. Disable expired relationships (Daily)
  3. Fetch bounces (Hourly)
  4. Geocode and parse addresses (Daily)
  5. Process inbound e-mails (Hourly)
  6. Process Survey Respondents (Everytime cron job is run)
  7. Rebuild Smart Group Cache (Everytime cron job is run)
  8. Send Scheduled Mailings (Everytime cron job is run)
  9. Send Scheduled Reminders (Daily)
  10. Update Participant Statuses (Everytime cron job is run)
  11. Validate Email Address from Mailings. (Daily)

 

Thanks for visiting.