digitalFAQ.com Forum

digitalFAQ.com Forum (https://www.digitalfaq.com/forum/)
-   Web Hosting (https://www.digitalfaq.com/forum/web-hosting/)
-   -   How to setup a cron job in cPanel? (https://www.digitalfaq.com/forum/web-hosting/5301-how-setup-cron.html)

Brent 08-25-2013 08:48 PM

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.

kpmedia 11-12-2013 07:47 AM

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:


Need a good web host? — Read our 2018 Review of the Best Web Hosts
Quite often, problems with web sites are caused by having a rotten web host. Worse yet, many hosts try to blame you (the customer) for the problems! So dump that lousy company. Say goodbye to slow sites, unresponsive support techs, and downtime. Find yourself a new host today. Whether you need shared, reseller, VPS, semi-dedicated, cloud, or dedicated hosting, something on our list should be a good upgrade for you.


MikeDVB 07-19-2016 09:41 AM

Quote:

Originally Posted by kpmedia (Post 28836)
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:


Need a good web host? — Read our 2018 Review of the Best Web Hosts
Quite often, problems with web sites are caused by having a rotten web host. Worse yet, many hosts try to blame you (the customer) for the problems! So dump that lousy company. Say goodbye to slow sites, unresponsive support techs, and downtime. Find yourself a new host today. Whether you need shared, reseller, VPS, semi-dedicated, cloud, or dedicated hosting, something on our list should be a good upgrade for you.

It's not really so important how often the cron runs as much as how resource intensive the cron is. If the cron is a heavy-hitter running it every minute is obviously going to be a bad idea.

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
Executing a PHP Script through the web server:
Code:

wget -O /dev/null http://www.yourdomainname.com/your-script-cron-folder/cron-file.php
At the end of the day the result of both methods is the same - the script is executed and performs its tasks. The difference is that the first simply invokes the PHP interpreter to run the file without involving the web server, HTTP connections, headers, etc... The second actually makes a request to the web server invoking all of the aforementioned overhead.

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 :).


All times are GMT -5. The time now is 03:44 PM

Site design, images and content © 2002-2024 The Digital FAQ, www.digitalFAQ.com
Forum Software by vBulletin · Copyright © 2024 Jelsoft Enterprises Ltd.