Fix high CPU consumption in WordPress

مدونة AiroServer

Fix high CPU consumption in WordPress

WordPress is the most powerful platform for professional bloggers and static websites. If you have been using WordPress on shared hosting or a virtual private server for some time, you have probably encountered CPU usage errors.

CPU

How to reduce your WordPress CPU usage without increasing server resources? Excessive CPU usage can cause your server to crash and your site to become unavailable, and may even affect your Google ranking. Whether your traffic is high or normal, there may be other reasons why your site causes CPU consumption in the server.

To avoid this, you need to keep the following things in mind:

1-Extensions

The priority is to remove unnecessary plugins from your WordPress website. Sometimes installed plugins can cause CPU usage. Some suggest that you use a maximum of 3 or 4 plugins, but in some cases, it is not possible to use limited plugins. It’s really hard to know which plugin is using CPU but you can get some information from the logs. If needed, you can view the reports through WHM/Server Status/Daily Process Log. the

CPU

In the above scenario, we should focus on correcting and optimizing the plugins and visual effects of the site and optimizing the loading of the blog homepage. You should also focus on things like displaying essential pages and avoid eye-catching pop-ups and related post plugins.

Try to avoid plugins like “Yet Another Related Posts Plugin (YARPP)” which have many problems in their code.

Tip: You need to clean your WordPress files and site by removing extra plugins.

2-Using the cache plugin

Currently, there are two efficient cache plugins on the market. Meanwhile, some people suggest W3 Total Cache or WP Super Cache. We recommend installing the WP Total Cache plugin, which is free and has some advanced features.

3-CloudFlare service

CloudFlare is a free CDN service that is very efficient and helps your websites load well and handle some CPU load. It also prevents DDos attacks on your website by hiding your real server IP address. It is suggested to everyone to use CloudFlare and prevent DDos attacks on their site.

4-Optimizing Cron Jobs (wp-cron.php)

Cron jobs are specifically dedicated to getting pings and page requests from the server. After installing WordPress by default, Con Jobs pings the server at certain intervals, which causes additional load and requests on the server. Fortunately, this is by no means a necessary action. So you can set the ping interval to a higher limit.

If you get 50 visitors to your site every hour and each of them reads 2-3 pages, wp-cron.php will be called that many times.

50 x 2.5 = 125 times per hour

125 x 24 = 3,000 times per day

3000x 30 = 90,000 times per month

RSS Feed autoimporter plugins also place a heavy load on server performance and memory.

How to optimize wp-cron.php?

First, you need to prevent wp-cron.php from running on every page. Do this by opening the wp-config.php file (in the folder where WordPress is installed) and adding the following line near the top of the file.

define(‘DISABLE_WP_CRON’, true);

What it does is it tells the WordPress engine not to run the wp-cron.php script on every page of the site, essentially disabling it. Next, you need to create a way to run the wp-cron.php file regularly. Now you need to create a way to run wp-cron.php normally. Create a cron job in cPanel that runs every hour and executes this command.

wget -O /dev/null http://www.example.com/wp-cron.php?doing_wp_cron

5-Using light themes

Light and simple themes also affect CPU usage and load. There are tons of themes for built-in features like sliding pages, ads and notifications, related posts, etc. to add to your site and the number of features you use will increase your server load time.

There is also a popular theme called Genesis that is running on thousands of reputable blogs. Whether you are a beginner or an advanced developer, Genesis provides a secure and search-engine-optimized foundation that can be of great help in managing your site.

6- WordPress database optimization

The database is the soul of every website and blog. The database is a part of MySQL and contains all the data of your site, such as sorting URLs of posts and meta information, etc. A poorly optimized database table can annoyingly clog your blog, using up unnecessary space to store unwanted data, which slows down your blog.

7-Compressing/merging the images in the posts

There is a saying that “a picture can say a thousand words”. When it comes to blogging, images are the most important factor in attracting readers’ attention. On the other hand, it can also be used to get inbound search engine traffic.

But inserting too many images not only slows down your blog but also annoys your readers. Minimize the maximum number of images you add to your blog as much as possible. Alternatively, you can host all your images on a subdomain that won’t affect your homepage speed, so the server will respond faster.

There are many image optimization tools to add to cPanel, and you can depend on any of these free tools or use third-party programs. Also, if you are posting long articles that have dozens of images, you can split the post into 2 or 3 pages depending on the length of the article. If you get hundreds of comments per post, you can use this method in the comments section as well.

8-Update functions

Many plugins release newer versions at regular intervals. Some themes are also updatable. Here, if you don’t update these functions properly, your blog will automatically get a lot of update requests whenever you load your blog. So update every plugin and theme (including WordPress) as soon as possible.

In short, always keep everything up to date. If an update is available, you should always do it because updates include security improvements and bug fixes.

I hope you have benefited from this article.

Find More Articles...

Whats New?

arAR