Adding CRON Job to your Cpanel
If you need to delete temporary files once in a while, or you want to perform database backups on a regular bases, you can do that using cron jobs. What cron job do is simply access your script or perform specified command in a specified period of time.
You've probably already noticed Cron job section in your hosting Cpanel or other hosting application. So what do you need to do to set up a Cron job?
Then in Cron job, you choose the period of time.
- * * * * * - every minute
- 0 * * * * - every hour when minute == 0
- 0 5 * * * - every day when hour == 5 and minute == 0 (05:00 am)
- 0 0,12 * * * - twice a day at 00:00 am and 12:00 pm
And then depending on your hosting configuration, you can try one of this ways to make your script work:
#before real commands, some optional parameters #add this i the end of you command, so you won't get emails after every successful cron job &> /dev/null #add this to create error logs if you can't get your cron job to run correctly 2>>/home/username/public_html/error.log #So ways to run a php script, of course username is your username not just a word #some paths may differ again based on your hosting configuration, #contact your hosting for mor einformation #or use wget or lynx commands below # with Easy Apache 3 which your hosting probably have php /home/username/public_html/cron.php #Optional flag if you get errors like php is directory from command above php -q /home/username/public_html/cron.php #for PHP4 /usr/local/php4/bin/php /home/username/public_html/cron.php #without Easy Apache 3 #for PHP5 /usr/local/php5/bin/php5 /home/username/public_html/cron.php # for PHP4 /usr/bin/php /home/username/public_html/cron.php #you can also modify your PHP script by adding this line below #to the begging of your script #!/usr/bin/php #and then saving your file as .sh file and adding this command to cronjob /bin/sh /home/username/public_html/file.sh #if nothing works you can always use wget command and acces your file externally #using lynx command lynx --dump http://domain.com/cron.php #using wget commang. --spider parameter is used so files won't be downloaded, #so no unnecessary files will be stored wget --spider http://domain.com/cron.php #simplest ways to set mysql backups #create backup mysqldump -u mysql_user -ppassword database_name > backup.sql #restore from backup mysql -u mysql_user -ppassword database_name < backup.sql
On some hostings there is a problem running php script with php -q. Possible reason is if you use mysql connection in your php script and you use localhost as host to connect to. Using your external host to connect to mysql in your script might solve this problem.
You may also be interested in:
Powered by BlogAlike.com