What is Cron Job?

Cron is a daemon that executes commands at specified intervals. These commands are called "cron jobs." The Cron daemon is available on Unix, Linux and Mac servers. Windows servers use a Scheduled Task to execute commands.

Cron Job Command Basics

The way you set up a CRON job on your server depends on what software you are using to manage your hosting account. Some web hosting control panels (such as cPanel or Plesk) offer a graphical user interface (GUI) which makes it much easier to set up the scheduled task. If you do not have a GUI available, you will have to enter the necessary commands using Telnet or SSH.

A quick search on the Internet for 'cron' followed by the name of your web control panel should yield plenty of articles that tell you how to physically set up a new CRON job, but it is usually fairly self-explanatory if using something like cPanel or Plesk.

In any case, a CRON job is made up of 2 main elements: a command to be run, and an interval definition (i.e. something that tells it how often to run). You might also be asked to provide an e-mail address to which any error messages or other output can be sent.

The command to run is made up of 4 parts:

  • An executable (i.e. a program that is capable of running PHP scripts)

  • One or more configuration options (specific to the executable)

  • An output path (where to put any output from the script)

  • A URL (the script to be called)

In the following example, the crontab command shown below will activate the cron tasks automatically on the hour:

0 * * * * wget -O - -q -t 1 "http://www.yourwebsite.com/index.php?option=com_ipmapping&task=cron.sync&secret=YourSecretKey"

The 0 * * * * part in the example above is the time when the cron job is going to happen. The following schematic tries to explain the general crontab syntax:

[Important]Important

Any line breaks which may be shown in the above examples are included for formatting clarity only. One should not have a line break in the command line!

    # +---------------- minute (0 - 59)
    # | +------------- hour (0 - 23)
    # | | +---------- day of month (1 - 31)
    # | | | +------- month (1 - 12)
    # | | | | +---- day of week (0 - 7) (Sunday=0 or 7)
    # | | | | |
    * * * * * command to be executed

The frequency with which one wishes a specific script to run, should be carefully evaluated. Running it too often when there is nothing much to do is probably wasteful of system resources. On the other hand not running it frequently enough means that the expected actions are not 'up to date'. Generally once an hour is more than adequate in our tests, especially since we used to manually perform the task twice or three times a day.

Trouble shooting cron

If your cron task is not working, you should:

  • Make sure your website can be triggered via your browser: Click on your cron URL. That will trigger it manually via your browser so you will see if this URL can be reached or not.

  • If you use a third-party SEF component, your website may redirect the current page to the SEF one may break the cron service. So you can either configure your SEF component to not transform non-SEF into SEF URLs or directly write your SEF cron URL on the cron interface.

  • Make sure your website can be triggered by the outside: If you have an .htaccess with password protection, your website will obviously not accept to be triggered by an anonymous user.

  • If you use a security component on your Joomla website and use a remote cron facility, this component might block the cron task. If you are using RSFirewall, you could try disabling the DoS protection from the Components => RSFirewall => Configuration => Active scanner configuration options.

  • Sometimes cron jobs can't trigger an URL including a "&" (see above) or can only trigger a script (instead of an URL). In that case, you should create a file with a suitable name at the root of your website including the code below:

    <?php
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,'http://www.yourwebsite.com/index.php?option=com_ipmapping&task=cron.sync&secret=YourSecretKey');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true);
    curl_setopt($ch, CURLOPT_AUTOREFERER,true);
    echo curl_exec($ch);
    curl_close($ch);
    [Important]Important

    Any line breaks which may be shown in the above examples are included for formatting clarity only. One should not have a line break in the command line!

    Then configure your cron to trigger that script.

    Please don't forget to replace 'yourwebsite.com' by the URL of your own website.

  • Make sure that there is no system cache storing up your pages accessed by a front end based cron task. If there is the cron task will only work when the cache entries expire, which will depend upon the cache settings.

Go To Top

Joomla! Debug Console

Session

Profile Information

Memory Usage

Database Queries