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.
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.
If you put “> /dev/null 2>&1” at the end of the cron job command (or any command), the output will be discarded.
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:
- day of 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.
Command to run a PHP5 cron job:
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:
Command to run a CGI cron job:
Command to run a shell script cron job:
Note: It is good practice to not type your password out in the follow commands but to simply use the -p flag alone and have the system prompt you for the password. This is way your password stays secure and is never on the server as plain text.
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)
Command to run for a PHP5 cron job:
Command to run for a PHP4 cron job:
Cron job limitations and Solution is here:
you can use
ini_set to bump the
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.
Enjoy your business with
without hassle 🙂