How to Fix High CPU Usage Problem in WordPress?



I currently use a hostgator business plan server also bought an ecommerce theme from themeforest and recently i make site. My visitor does not come to the site yet, whenever the Visitor gets 4 or 5, the CPU Usage becomes 100% along with Entry Processes and I/O Usage. If no visitor come, Then it also shows 100%. When it gets 100%, Database shows Establish Error.

The work i have done for Solving the Problem…
• Jetpack by
• Akismet Anti-Spam
• Wordfence
• Caching plugin
2. From Some days, using Droplet 2 VPS from Digital Ocean, But the same result Again Showing.

  1. Besides, I uninstall all the plugin themes and delete the data base, again installing the Wordpress and keeping the default theme activated for 3 days, but the results were the same, the CPU Usage was 100%
  2. For a while, i just keep one indix.html file, then again re-install it. But the Same Result Happens.
  3. Also tried blocking Bad bots via .htaccess

However, after installing the WordFence Security Plugin, I have seen some problems, some visitors from various IPs have come from different countries, but they do not show the Google Analytics and the link that is not linked to my website. The type such as Visit my site, by creating link using some random keyword. And Per minute 30-40 hits to my site from different IP/Country. When I block those, then uses another IP. It run Continuously.

My server configuration

  1. php version-7.0
  2. max_execution_time - 360
  3. memory_limit - 264M
  4. post_max_size - 64M
  5. upload_max_filesize - 64M

To be Noted: Another Website Running Using the same Server where Real time Visitors 200+ and CPU usage only 2%

Now what I have to do? Give the Exact Solution that will surely work to solve the Problem Permanently.


Hello @Mourin516

The exact solution is a bit difficult to give without seeing the logs or the database. :slight_smile:

But from what you are saying (that when it shows “error establishing database connection” it reaches 100% CPU), most probably it is something related to the database, this is what I would try:

  1. first, try to optimize&repair the database. Either through cPanel or MySQL console if you know how, either directly in WordPress, following these steps:
  • add the following line in your wp-config.php file. Add it just before ‘That’s all, stop editing! Happy blogging’ line:
    define('WP_ALLOW_REPAIR', true);
  • then in your browser to: (replace with your website link)
  • click the “Repair and Optimize Database” button in the page that appears.
  • try again to access the website and check the CPU again
  1. Enable WordPress debug log: (also define SAVEQUERIES as true, as explained in the article, to see all queries that run) and try to see if there are MySQL warnings or errors in the log.

Most probably the website is affected by a DDoS attack. I know this because only in case of DDoS attacks, the website has visits but they do not show in Google Analytics (many hidden visits, causing multiple connections limit error which result in highest CPU). It happened to me too some time ago and I know it is quite hard to track because the attackers avoid being detected by Google Analytics libraries :frowning:

The solution is to use a third-party buffer like CloudFlare (the basic package is free) to block DDoS attacks. If you wish, I will send in a private message a link to an article which explains in detail how to check if your website is under a DDoS attack.

If you discover anything suspicious in the logs, just post it here, we’ll try to help.

I hope it helps a bit,


It could be the memory limit. Change/update memory limit to 1GB should help regarding to if the theme requires more memory


I think that you can change to 64mb but I am not sure.



This is an issue with the theme or some plugin in yhe theme, most developers don’t think at optimizing things, they just want to sell, unfortunately for you you found one or more of them.

Regards. Tibi - FWD.