Scheduling a real cron job
Log into your cPanel.
Navigate to the Advanced section.
Click Cron jobs.
The Cron Email section will send an email out after the Cron has finished.
Syntax
Here is a simple cron job:
There are two main parts:
- The first part is “0,30 * * * *”. This is where we schedule the timer.
- The rest of the line is the command as it would run from the command line.
The command itself in this example has three parts:
- “php”. PHP scripts usually are not executable by themselves. Therefore we need to run it through the PHP parser.
- “/home directory/public_html/folder-name/admin/cron.php”. This is just the path to the script.
- “> /dev/null 2>&1”. This part is handling the output of the script. More on bellow.
Handling the Output
If you do not handle the output of the cron script, it will send them as e-mails to your user account on the server.
Discarding Output
If you put “> /dev/null 2>&1” at the end of the cron job command (or any command), the output will be discarded.
Timing Syntax
This is the first part of the cron job string, as mentioned above. It determines how often and when the cron job is going to run.
It consists of five parts:
- minute
- hour
- day of month
- month
- day of week
Here is an screenshot for better understanding:
Common Settings include every minute to once a year.
Enter in the desired Command and click Add New Cron Job button.
Command lines. Examples only! Bold sections must be changed.
Note:You may need to adjust /home/ to /home#/ depending on the home directory your account resides on. To view the home directory for your account simply view the stats column on the main cPanel page of your account and look for the home directory.
PHP
Command to run a PHP5 cron job:
php /home/username/public_html/cron.php
Optional flags are sometimes required for a PHP cron job:
php -q /home/username/public_html/cron.php
Command to use a specific php.ini file:
php -c /home/username/public_html/php.ini /home/username/public_html/myscript.php
Command to GET a remote file:
/usr/bin/GET http://www.example.com/file.php
Perl
Command to run a CGI cron job:
perl /home/username/public_html/cgi-bin/file.pl
SSH
Command to run a shell script cron job:
/bin/sh /home/username/public_html/file.sh
MySQL
Command to import a database:
mysql -u mysql_user -ppassword database_name < backup.sql
Command to export a database:
mysqldump -u mysql_user -ppassword database_name > backup.sql
Custom Installations without Easy Apache 3 (VPS/Dedicated)
PHP
Command to run for a PHP5 cron job:
/usr/local/php5/bin/php5 /home/username/public_html/cron.php
Command to run for a PHP4 cron job:
/usr/bin/php /home/username/public_html/cron.php
Cron job limitations and Solution is here:
ini_set
to bump the memory_limit
and max_execution_time
(ususally infinite in command though) – that will be help you to do but I think EasyCron will be good for you so you can choose the service from here to overcome all complexity.