Loading...
Changes Saved.
Error Occurred!

KnowledgeBase

Cronjobs: How To

I.    The Basics of Cronjobs
II.   Control Panel Specific Instructions
III.  Manual Setup
IV.  Windows Scheduled Task Setup
V.   An Alternative to Cronjob setup
VI.  Additional Resources

The Basics of Cronjobs

A cronjob is a simple server script that allows your server to perform a certain function, such as executing a PHP script, at timed intervals. Many of our products come equipped with one or more cron scripts that are designed to be activated in this way in order to carry out timed or automatic tasks, such as sending or receiving email. You can recognize them easily, as their file names all begin with "cron."

 

In order to make use of cron functionality, you must follow the products' installation instructions exactly; specifically, you must set the file permissions for each script whose name begins with "cron" to 755, which allows the file to be executed.  The installation instructions for each product list the locations and names of the "cron" files.

Additionally, on some servers you may need to open up these cron scripts in a text editor and change the first line of the file to reflect your server's path to PHP, if the
server does not use the standard location of '/usr/local/bin/php' for PHP.. If your cron scripts are not running as they should, consult your web host or server admin to make sure the path to PHP is correct.
 

 

Control Panel Specific Instructions

 

  • Plesk 8.3 (Linux)
  • Plesk 8.3 (Windows)
  • Cpanel
  • H-Sphere

 

In any of these control panels, you will have options to enter how often you wish for the command to run along with a command to run.The command should be the path to the file you are wishing to run. You would enter would take the format of:

php -q /home/path/to/www/folder/cron.php           (Where the path to the php file you wish to run is in green.)

or 

/usr/local/bin/php /home/path/to/www/folder/cron.php           (Where the path to php itself is in purple and the path to the php file you wish to run is in green.)

You may also have to edit the first line of the php cron script you are running with the cronjob so that the first line reflects the path to PHP on your server, if your server does not use the standard location of '/usr/local/bin/php' for PHP.

 

Manual Setup & Common Formats

If you do not have a control panel for your web site or do not have a control panel that supports setting up cronjobs you will have to manually setup the cronjob.While not overly complex, it does require that you know certain things about your server.So if you are unsure of what you are doing it is highly recommended to contact your web host or system administrator for help, as our technicians are not able to provide support for server configuration.

Assuming your server is setup for cron, you should be able to type (in the command line):

crontab -e

This will show you what you currently have in your crontab.You are now able to enter a new crontabe entry.Some possible formats for your crontab entry are:

*/5 * * * * /usr/local/bin/php /home/path/to/www/folder/admin/cron.php

(Orange is saying to run every 15 minutes.Green is the path to php. Blue is the path to the php page you wish to run.)

Another option could be:

*/5 * * * * php -q /usr/local/bin/php/home/path/to/www/folder/admin/cron.php

Orange is saying to run every 5 minutes.Green is the path to php. Blue is the path to the php page you wish to run.

You may also have to adjust the first line of your php page you are running with the cronjob so that the first line has the path to PHP.


Windows Scheduled Task Setup

On a Windows server you will instead have to use "Scheduled Tasks".  The windows task scheduler can often be found in the Windows start menu,  under All Programs->Accessories->System Tools->Scheduled Tasks.  To run a php page using the windows scheduled task, you will want to create a new scheduled task, and in the "Run:" field, you will insert the path to PHP on your windows server, followed by the path to the php page you would like to execute.  In the "Start in" field, enter the path to the directory where PHP resides on your Windows server.  For example:



An Alternative Option: 3rd Party Website Monitoring Tools

Instead of setting up cronjobs, you can use a website monitoring service to emulate your cronjobs.  Such services are used to automatically check your website to see it if it functioning properly.  To do so, you would have the service monitor the cron file you would like executed.  For example, http://www.example.com/software/cron.php.  Each time the website monitoring service accesses the cron file, it will run, just as if you had a cronjob setup.

Additional Resources & Assistance

With the wide range of hosting setups and servers you will have to contact your web host or system administrator for further assistance with cronjobs.Below are a collection of useful links for further research as well.

http://www.linux-tutorial.info/cgi-bin/display.pl?78&0&67&0&3

http://www.linuxjournal.com/article.php?sid=3290

http://www.4webhelp.net/tutorials/misc/cron.php

http://www.phpfreaks.com/tutorials/28/0.php




Related Articles