How to solve wp-cron.php high CPU usage?
It is known that wp-cron.php file can cause high CPU usage on high traffic WordPress sites. This can also occur on sites hosted on shared or VPS hosting when they receive more traffic than usual at short period of time (traffic spikes).
Typically, every page load calls wp-cron.php to be executed and to run any tasks that are scheduled to be executed (like posting scheduled posts, plugin or theme updates, clearing caches on various caching plugins, sending email notifications etc). This basically asks WordPress: Is it time do do anything now? And then WordPress checks for pending tasks and if there’s nothing to do typically answers with: sorry, but there’s nothing to to at this moment… Try a bit later… and this probably happens in 99% cases. So this wp-cron.php literally nags WordPress all the time with those requests. On low traffic sites, this is perfectly fine but on high traffic sites (or sites with traffic spikes) this can cause higher resource usage, make problems with your hosting (vps/server) and decrease your site performance.
Best way to prevent this wp-cron.php activity is to stop it from running the default way (on every site visit) and then just run it using cron when according your needs.
To stop WordPress from executing wp-cron.php after every page visit, simply add this single line to the end of your wp-config.php file:
That’s it! This will lower the CPU/resource usage instantly. But it’s not recommended to never execute wp-cron.php since your WordPress plugins and themes won’t be updated and your scheduled posts won’t be posted etc.
Here is the commands that you can use to run wp-cron.php using a real cron:
/usr/bin/wget -q -O - http://www.yoursite.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1
There’s no general rule as for the frequency of this cronjob since every site and setup is different. Everything from once per day to every minute is fine but it really depends on your system. If you have tasks that run every 10 or 15 minutes you should probably setup cron to run every 5 minutes. It’s still quite frequent but it won’t happen that you get several cron runs in couple of seconds.
To setup cron at cPanel hosted site login at cPanel, click on Cron Jobs icons and there add a new cronjob like this:
April 16, 2016 - 9:08 am
You solved my problem.
Tnx very tnx.
October 7, 2016 - 7:41 pm
Thank you for your help.
There is one small mistake that I ‘ve taken a while to realize: The true in the define statement shoud be without quotation marks.
Mark @ GRAVELBIKE
May 2, 2017 - 5:06 pm
This is really good info–thank you.
Just to be clear, wp-config.php needs to be updated AND the cron job also needs to be added, right?
May 9, 2017 - 9:33 pm
March 16, 2020 - 8:14 pm
Thanks a lot, really helpful for me, because i was facing High CPU resources issue with wp cron . i just disable it and my cup is cool down, but facing plugin update issue.