How to setup a cron job in cPanel?
This demo assumes you've already logged in to cPanel. Now let's learn how to setup a cron job.
1) Click the Cron Jobs icon http://www.digitalfaq.com/forum/imag...ene03_1-21.png 2) Enter the email address where you want the cron job results sent after each time it runs http://www.digitalfaq.com/forum/imag...ene04_1-20.png Now you have to define exactly when and how often you want the cron job to run. This is made easier by using one of the pre-defined or common settings. http://www.digitalfaq.com/forum/imag...cene08_1-7.png Notice that by choosing a common setting, all fields are filled in automatically. This also helps you understand what each field means. 3) Let's choose Once a week http://www.digitalfaq.com/forum/imag...cene12_1-4.png 4) Next, enter the command of the script you want to run, including the path (from root) http://www.digitalfaq.com/forum/imag...cene14_1-6.png 5) When ready, click Add New Cron Job http://www.digitalfaq.com/forum/imag...cene15_1-7.png That's it! The cron job has been set as you can see here http://www.digitalfaq.com/forum/imag...cene17_1-5.png You can create additional cron jobs, and edit or delete existing ones http://www.digitalfaq.com/forum/imag...cene18_1-4.png This is the end of the tutorial. You now know how to setup cron jobs in cPanel. |
Additional Tips:
A lot of CMS plugins -- so-called "premium" WordPress plugins especially -- give bad advice when it comes to manual cron jobs. I've seen some insist the cron run every 1 or 2 minutes -- or even a seemingly reasonable (but not really!) 5 minutes. On a shared server, this is unreasonable. It causes far too much server load, and is adequate reason for suspension. You'll need a VPS or dedicated server for that much use. Every 30 or 60 minutes is reasonable. May 15 or 30, but even then, not really. Pick your cron job times carefully! :old:
|
Quote:
If the cron task being executed itself is light-weight running it every minute shouldn't be a problem at all. I know personally on my sites I have several 1-minute crons as every time it fires off it uses so little resources when there's nothing for it to do that it's not a problem. When it comes to the command - one thing to keep in mind is that it's always going to be best to run the file locally than to execute it through the web server. Executing a PHP Script locally: Code:
php -q /home/youraccountname/public_html/your-script-cron-folder/cron-file.php > /dev/null Code:
wget -O /dev/null http://www.yourdomainname.com/your-script-cron-folder/cron-file.php Furthermore by invoking them locally you can many times place the cron script outside of public view so that it cannot be activated by third parties/maliciously. It is up to your software to support this though. One last thing - if you decide to use WGET make sure to send the output somewhere like /dev/null otherwise you're going to very quickly find your account home directory filling up with the saved output from your cron job. Hopefully this helps :). |
Site design, images and content © 2002-2024 The Digital FAQ, www.digitalFAQ.com
Forum Software by vBulletin · Copyright © 2024 Jelsoft Enterprises Ltd.