Site Administration Page 2 - Cron Job Tutorial: Crontab Scheduling Syntax and Script Example |
First upload the PHP script to the root directory of your website. Then log in to your web hosting account. Go to the crontabs section. Bear in mind that different web hosting companies will have different methods for configuring cron. For a common crontabs feature, such as that used by Agilityhoster and other hosting companies, take a look at the screen shot shown below:
Suppose you would like to implement the "file delete script" discussed previously, and you want to run it every 10 minutes, every hour of every day, every month, and every weekday. First, enter the command (this is simply a full server path to the file delete script at the root directory): /home/www/php-developer.org/deleteallfiles.php Then, make sure the following items are highlighted:
Finally, click "Set Cron Job." When this is successful, you will receive a notice that the cron has been successfully created or added. Screen shot: Configure Cron Job in Go Daddy Hosting to Run PHP Scripts Other web hosting companies, such as Go Daddy, offer a significantly different set up for setting or configuring cron jobs. If you have websites hosted in Go Daddy, follow the procedure below: 1. Log in to your web hosting account, and click "My Account." 2. Under "My Products," click "Hosting." 3. Under "Products == Web Hosting," click the "Launch" button for the website on which you would like to implement cron. Clicking this will take you to the "Hosting Control Center." 4. In the hosting control center, go to "Content" - "Cron Manager." 5. Click "Create Cron Job." You will then see a screen that looks like the image below:
6. Under "Cron Job title," you can assign a name to it, such as "Testcron." 7. In the "Command," Go Daddy requires the following command syntax for running PHP scripts using Cron Job: For PHP 5 web hosting accounts: /web/cgi-bin/php5 "$HOME/html/thisisyourphpscriptatrootdirectory.php" For PHP 4 web hosting accounts: /web/cgi-bin/php "$HOME/html/thisisyourphpscriptatrootdirectory.php" Suppose you have a folder named "restricted" in your website root directory. And you would like to run a MySQL database backup script named backupmysql.php, which uses PHP 5. Also you would like to run this backup script on an hourly basis (in reality you would set this up to run monthly, perhaps). This is how you will configure this cron: Cron Job Title: Testcron Screen shot:
Securing Your Cron Scripts The following are tips that can you use to secure your cron PHP scripts:
blog comments powered by Disqus |
|
|
|
|
|
|
|