If you are using a content management system to create a website, it is likely that you will eventually encounter a situation where you need to set up a Cron job. Cron is a program installed on Unix / Linux based servers that allows users to schedule tasks to be run automatically at specific dates or times. The name "Cron" is derived from the Greek word for time - chronos. Since most people use shared hosting, this guide will provide the basics for setting up your own crontab and automating tasks with your web hosting provider on a shared server...

You can actually run Cron maintenance by entering, for example, the URL "http://www.yourwebsite.com/cron.php" into a web browser. But we want to get this done automatically, so we need to call on the help of the Lynx browser. Lynx is a text browser that is often installed on servers. You will need to contact your hosting provider to make sure that they have Lynx installed (most probably do).

Once you know that Lynx is installed, you will need to find the configuration panel for setting up a Cron job in your hosting account. If your web host uses Cpanel, you will probably see something like this:

Image

The first thing to do is enter the command. The following example is the command I use to make Lynx run cron.php:

lynx -source http://www.yourwebsite.com/cron.php

You may need to adjust this command depending on your hosting provider .

The next step is to decide on a schedule to have this Cron job run. Running Cron does use system resources, so you don't want to have it running every minute if you don't need to. It is up to you to decide on an appropriate schedule for having each Cron job run. Understanding the format for entering a schedule can take a little getting used to. Here is a quick rundown on scheduling options that can be entered:

Minute — any integer from 00 to 59 (specifies the minute the job will be run on)
Hour — any integer from 0 to 23 (specifies the hour the job will be run on)
Day — any integer from 1 to 31 (must be a valid day if a month is specified)
Month — any integer from 1 to 12
Weekday — any integer from 0 to 7, where 0 or 7 represents Sunday

The asterik (*) specifies that the task should be run every time for any sub-constraint. This statement doesn't even make sense to me so let's just have a look at the examples to figure it out. You can also use the command */ to have jobs run every interval. Here the examples to help you get the hang of it.


Run cron.php task every 30 minutes:

 */30               lynx -source http://www.yourwebsite.com/cron.php


Run cron.php task once a week at 1:00 am every saturday (you can see that saturday is represented by 0):

00   1       0       lynx -source http://www.yourwebsite.com/cron.php


Run cron.php task on the first day of every month at 12:00 am (midnight) :

 00   0   01     *       lynx -source http://www.yourwebsite.com/cron.php


 Here is an example how to set up a Cron Job accessing PHP directly (as a command line command, not through a broeser like lynks). This is an example for the late Feedgator component.


Run task every 12 hours at midnight and at noon:

00   1       0  

/usr/local/bin/php /home/yourusername/public_html/cron.php >> /dev/null

This Tutorial is compliant with Joomla 1.0.X!