We all have 'those' jobs we have to do every now and again (washing the car, tidying the house anyone?) and online this is no different. For example, your website needs a sitemap and you are adding pages everyday. Do you really want to be having to update this sitemap manually - all of the time?! This is where Cron jobs really come into their own! A Cron job is basically an 'alarm clock' for a piece of code to run automatically. Cron jobs are part of Linux so here at Peter's Web all of our accounts come with the ability to create multiple Cron jobs.
There are multiple elements to a Cron job :-
- TIMING - How often do you want the Cron job to run? Cron jobs can be set to run every minute to once yearly depending on what you would like the job to do.
- COMMAND - What do you want the Cron job to do? This can be a simple command or a file that you would like the command to execute.
- ACTION - The output of the script, do you want the Cron job to write the output to a file?
The steps to setup a Cron job are : -
- Load into cPanel
- Find 'Cron Job' option on the menu, you will find this in the advanced category around 3/4 down the menu page.
- Within the Cron Job option page you can assign the running time of the job to your own specification - we recommend that you use the drop down menus provided if you haven't scheduled a job before.
- Below the timing options eneter the command you wish the job to run in the 'command' box, if you are running a php script please 'php -q' followed by the pass of your script. Note that this will start with /home/yourusername.
- Click 'add new Cron job'
If you have any questions about setting up Cron jobs - they can be quite fiddly, please open up a support ticket (open a ticket) and we will be more than happy to help you.