high cpu resource useRecently when I was logged into my cPanel account I would notice that my CPU usage would jump to 98%, and it would sit at that rate for about 45 seconds strait. It seemed to happen at various times, not real consistent, but often.

The 98% for 45 seconds is not a massive amount of time, but long enough considering this is a cheap shared hosting account to warrant further investigation.

Here is a screen shot of my CPU use for 7 days. You can easily see where I fixed it as the CPU use dropped considerably:
CPU 7days

This one is entry processes. I don’t get a lot of entry processes, but you can see where it dropped as well:
Entry Processes 7 Days

This one is faults, and you can definitely tell where it dropped here as there are barely any after fixing it:
Faults 7 Days

This was a tough one that took a bit of time to figure out. I do run more than one website off this account, and at first I thought my cache plugins were causing this when they were generating html, compressed gzip html, css, compressed css, js and compressed js files.

So, I turned off the compressing of those files, and left the cache at only uncompressed files. I do use Incapsula, which is similar to Cloudflare that will compress those files on the fly anyway with the same results only Incapsula does the work instead of my hosting account.

Unfortunately that did not help. So, the next thing I did was increase both my hosting account php memory limit to 512 MB’s, and WordPress to the 512 MB’s by adding the following to the wp-config.php file:

By default at the current time WordPress is pre-set to 40 MB’s, which is pretty darn small. In certain hosting setups and configurations even if your hosts php memory limit is set to more than this WordPress won’t allow anything larger unless you increase it with the line above in wp-config.php.

So, I thought maybe some process was maxing out the 40 MB limit and causing the CPU to spike because of this. I’ve seen this happen before with other CMS systems.

Unfortunately the 512 MB setting did not help the problem, but it definitely did allow me to use other plugins that required more than the 40 MB’s. So, I knew it was doing what it was supposed to.

At this point I had to get my thinking cap out, and do a little deep breathing, meditating, and heavy thinking. Not really, but that sounds good right?

What finally solved the CPU resource use, and brought it down to less than 20% on a regular basis (usually much less) was to disable the built-in WordPress cron that fires when someone visits a page, post, etc. automatically, and to set up a cron job in my hosting account to make it fire at a controlled and specific interval. I chose every 30 minutes for the time-being. I may end up changing that later, but so far it seems reasonable enough for this website.

The first thing I did was to disable the WordPress built-in cron by adding this line to the wp-config.php file near the top:

That disables it completely.

Then, I simply set up a cron job in my hosting cPanel account with the following command:

cPanel Cron Jobs Section:
Cron Job cPanel

That means as I said make the wp-cron.php fire off every 30 minutes. You would replace “MY-CPANEL-ACCOUNT” with your actual account login/name. And, mine is located in the subfolder blog (dialme.com/blog). If your WordPress is installed in your root/public_html folder (i.e.: yoursite.com) then, it would look like this instead:

For every 15 minutes instead of 30 then do this:

The >/dev/null 2>&1 part just means do not send and email notification every time this goes off. The -q is quiet. You probably don’t even need the -q part, but I use it so often for other commands it won’t hurt any.

Now check this one out. This is a single day of CPU resource use and look at that … much lower!
CPU Resource Use 1 Day

I have a feeling the built-in WordPress cron was causing various processes like php perhaps to get backed up and overwhelmed. Changing it to a manual cron job is a more controlled atmosphere that helps keep that from happening, or reduces it at the very least.

So, if you are seeing an increase in CPU resource use this could be your problem as well. It certainly is worth looking into. Change it, let it run for 24-48 hours and see if you notice a decrease like I have. If not you can always change it back if you want by deleting the cron job, and removing the define(‘DISABLE_WP_CRON’, true); from wp-config.php.

I should have done this along time ago.

About: Jeremy LeSarge - AKA: Ray (233 Posts)

I am the site owner and administrator of DialMe.com. I provide help and tips for Boonex Dolphin on the main part of this website where you will also find an assortment of other resources. Here, on the blog I write about a variety of topics surrounding WordPress, technology, social media/networking, SEO, and webmaster resources.