Why real cron job and why all the fuzz?
If you are running your own VPS or if you are on a shared hosting, you might want to keep your resources optimal without over-utilizing them.
Some shared hosting companies, such as Siteground, have claimed to be one of the best in the business. But then again, they provide you with limits on CPU resources that aren’t good enough for any regular user.
Let’s say that you have a website or two, with up-to 100 real visitors on a daily basis. And to have something like that, your website would have to be little bit popular, in which case there would be huge number of robots (good or bad) visiting your websites too, hundreds or even thousands – you never know.
So, each time someone visits (human or robot) your website, WordPress will trigger its in-built ‘wp-cron’ system. This will kick a huge impact on your CPU time.
You have exceeded the daily CPU Time limit of your account.
Seriously? For >100 real visitors a day, only! Yeah.
Anyway, the reason why this happens in most cases is the wp-cron, which, let’s remind ourselves, triggers the ‘cron’ script every time a robot or a human lands on any of your pages.
” Exceeding the CPU Time limit means that the execution of your script(s) takes too much CPU resources. “
When wp-cron runs, there could be other things running as well, therefore we must put and end to that by controlling the “cron” system.
The cPanel cron
If you have cPanel access, then you need to do the following steps:
1. disable the wp-cron within the ‘
To do that, you have to edit that file, and add this line:
2. Within the cPanel dashboard, click on the icon named “Cron Jobs” and configure your new cron job.
- under common settings you have to choose how often the cron will run
- everything else will fill in automatically, except the “Command” field
- “Command” part – here you need to enter this command in order for cron to work on your domain:
wget -q -O - http://yourdomain.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1
- Make sure to change the “http” to “https” if you use SSL, and the “yourdomain.com” replace with your own domain name.
The Linux way (“this is the way”)
For those people running their own VPS there shouldn’t be any difficulties, and pictures won’t be needed. It doesn’t matter if you run NginX, or LiteSpeed server or even Apache. “This is the way” 🙂
1. disable the wp-cron within the ‘wp-config.php’ file:
2. run command:
3. add the following line anywhere within the file:
*/30 * * * * wget https://yourdomain.com/wp-cron.php
The number “30” means that the cron will run every 30 minutes. In the image below I have set it to 15 minutes.
When you finish, your website will be nicely ‘CPU’ optimized, and you won’t have any problems with your shared hosting provider, or your VPS.
Have a nice day.