How to fix CPU problems in WordPress

how to optimize wordpress site

WordPress Heartbeat and Heavy admin-ajax.php Usage








How to fix CPU problems in WordPress

Update WordPress
----------------
If you’re not using the latest version of WordPress update now. Make sure you backup your site first!

Update Plugins
----------------
Updating your WordPress plugins to the latest versions can often reduce high CPU usage. If you’re running an old version take a moment to update now.

Avoid beta versions of plugins
------------------------------
Whilst it’s cool to be at the cutting-edge, only use stable versions of WordPress plugins. Sometimes early release versions (also known as alpha or beta) can have bugs in the code which can cause CPU spikes.

Install a caching plugin
-------------------------
Caching plugins such as W3 Total Cache and WP Super Cache can dramatically reduce CPU load by caching static copies of your pages on your web space. Static files use less CPU and memory. Keeping you within your shared-hosting limits.

Disable WP-Cron
----------------
WP-Cron manages all the scheduled events in your WordPress site. WP-Cron is a very common cause of high CPU loads as it is called every time someone visits your website. Disabling WP-Cron and replacing with a real cron job can drastically reduce CPU-load and prevent the chances your account is suspended due to exceeding your resources.

It can be simply disabled by add command [ define('DISABLE_WP_CRON', 'true'); ] at "wp-config.php" below line "define('DB_COLLATE', '');"

Only use plugins you really need
--------------------------------
Do you really need that plugin that constantly checks for broken links? – The more WordPress plugins you have installed, the longer your site will take to load. Deactivate and delete any plugin that you don’t need. Aim for just a handful of plugins. This will speed up your site and keep your visitors happy.

If you’ve disabled plugins you don’t need, and still have high CPU usage you’ll need to try debugging each plugin to see if it’s the cause of the CPU spike. First make sure you’ve taken a backup of your entire WordPress site (files and database). Now try disabling each plugin one by one until the CPU load has been resolved. Once you’ve found the faulty plugin you should hopefully be able to reenable the others without seeing the CPU problems.

Avoid buggy WordPress Themes
-----------------------------
A badly written WordPress Theme or one written with demanding features such as server-side image resizing can be CPU intensive. To rule out problems with your WordPress theme try the following:

Check error logs for problems. Login to cPanel and check the Error logs for errors.
Contact the theme developer and ask if there’s any known issues.
Disable any dynamic features built into the theme such as thumbnail resizing. Some WordPress themes have their own image resizing modules which can cause high CPU usage. If possible we recommend disabling them in favour of using the more efficient image resizing built into the WordPress core.

Reduce widgets 
--------------
There may be certain widgets that aren’t essential. Check them thoroughly and remove the ones that may not be beneficial for the readers. The more widgets you use the more strain you are enforcing on the server. Hence, to lower server load and CPU usage, get rid of unwanted widgets.

Lower PHP or Database calls
----------------------------
PHP scripts and database calls also consume a lot of CPU resource. Caching your sites helps but certain database/PHP calls cannot be avoided. Hence, you should go through the plugins documentation carefully and disable the unnecessary options.

Lower load on index.php file
----------------------------
At peak hours, your homepage may create a load on your server during the peak hours. To lower this load, ensure keeping your homepage simple. Try to lower the number of posts on your homepage and remove unwanted files, links and high resolution images. It would be even better if you choose a CDN service like Cloudfront


Use PHP 7
-----------
Switching to PHP 7 can dramatically speed up your WordPress website, reducing loading time and freeing up CPU and memory. We recommend testing a staging version of your website with PHP 7 before changing the production version. You could change PHP version from Cpanel 

Cpanel--> MultiPHP ManagerMultiPHP Manager

Disable XML-RPC uplaod
-------------

Add below rules at .htacess to prevent xmlrpc.php. This may prevent xmlrpc.php attack to your domain. 

# Block WordPress xmlrpc.php requests

order deny,allow
deny from all