WordPress Security Guide

Stop WordPress CPU Spikes Caused by Bots

If your WordPress site suddenly hits 100% CPU or your hosting shows many lsphp processes piling up, there is a good chance you are dealing with aggressive bot crawling or scraping. Here is how to verify it and reduce the load fast using only .htaccess and Wordfence Live Traffic.

Stop WordPress CPU spikes caused by bots

What problem are we solving?

When bots repeatedly hit WooCommerce categories, product pages, search URLs, or other dynamic endpoints, each request can reach PHP. That means cache is not always enough, and the site can start filling up with index.php processes.

The goal is to block bad requests as early as possible, before the full WordPress stack loads.

.htaccess Shield Blocks XML-RPC, empty user agents, and common scraper/headless browser tools.
Wordfence Live Traffic Helps you identify which IPs and request patterns are creating the bot wave.
You do not necessarily need Cloudflare or server-level access for the first emergency step.

How to confirm it is bots

1. Check Resource Usage / Snapshot

On cPanel hosting, especially CloudLinux-based environments, go to Resource Usage → Snapshot and look for these signs:

  • Many lsphp:/home/.../public_html/index.php processes.
  • Repeated requests to wp-cron.php.
  • CPU that stays high even when you are not actively testing the website.
cPanel snapshot with many bot requests
Example snapshot with repeated PHP requests.
CPU usage spike in cPanel
CPU usage staying high because of repeated hits.

2. Check Wordfence Live Traffic

Go to Wordfence → Tools → Live Traffic and look for patterns like:

  • The same page being hit repeatedly, for example /product-category/....
  • Lots of different IPs within a short time window.
  • IPs from unexpected locations.
  • Missing, strange, or automated user agents.
If you see many IPs such as 57.141.4.17, 57.141.4.61, 57.141.4.64 hammering the same URL, you are probably looking at a bot wave from a specific range.

The .htaccess snippet solution

Add the snippet below to your root .htaccess file, above # BEGIN WordPress.

  • Blocks xmlrpc.php, which is commonly abused by bots.
  • Blocks known scrapers and headless tools by User-Agent.
  • Lets you add IP ranges when you see a real bot wave.
Simple Anti-Bot Shield — Apache / LiteSpeed
# =======================================================
# Simple Anti-Bot Shield (Apache / LiteSpeed)
# Paste ABOVE: # BEGIN WordPress
# =======================================================

# 1) Block XML-RPC
<Files "xmlrpc.php">
  Require all denied
</Files>

<IfModule mod_rewrite.c>
RewriteEngine On

# 2) Allow Google
RewriteCond %{HTTP_USER_AGENT} (Googlebot|Google-InspectionTool|AdsBot-Google|Mediapartners-Google) [NC]
RewriteRule .* - [S=3]

# 3) Block empty / missing User-Agent
RewriteCond %{HTTP_USER_AGENT} ^$ [OR]
RewriteCond %{HTTP_USER_AGENT} ^-$
RewriteRule .* - [F,L]

# 4) Block common scrapers and headless browsers
RewriteCond %{HTTP_USER_AGENT} (curl|wget|python-requests|scrapy|aiohttp|httpclient|Go-http-client|libwww-perl|okhttp|node-fetch|axios|postman|httpie|PycURL|HeadlessChrome|PhantomJS|Puppeteer|Playwright|selenium) [NC]
RewriteRule .* - [F,L]

# 5) Block generic bot keyword except Googlebot
RewriteCond %{HTTP_USER_AGENT} bot [NC]
RewriteCond %{HTTP_USER_AGENT} !googlebot [NC]
RewriteRule .* - [F,L]
</IfModule>

# 6) OPTIONAL: Block attacker IP ranges
<RequireAll>
  Require all granted

  # Example:
  # Require not ip 57.141.4.0/24
</RequireAll>
Before editing .htaccess, keep a backup of the file. One wrong rule can cause a 500 error.

Do you need IP blocking for this to work?

Not always. If the problem is mostly “easy” scrapers, User-Agent rules may reduce the load enough. But if you are getting a bot wave with normal-looking User-Agents, IP blocking is usually what actually stops the flood.

In real incidents, IP blocking often creates the biggest CPU drop because it stops the request before it reaches WordPress or PHP.

How to block the correct IP range

Collect IPs from Wordfence Live Traffic For example: 57.141.4.17, 57.141.4.61, 57.141.4.64.
Find the common /24 range If the IPs share the same first three blocks, the range is 57.141.4.0/24.
Add it to the RequireAll block Start conservatively with /24 and do not block huge ranges blindly.
Example IP range block
<RequireAll>
  Require all granted
  Require not ip 57.141.4.0/24
</RequireAll>
Important: 57.141.0.0/24 does not block 57.141.4.*. A /24 range only covers the last block of that exact third block.

What not to do

  • Do not block Googlebot by IP. Google crawling IPs change and should not be guessed.
  • Do not block large ranges such as /16 without clear confirmation from logs.
  • Do not mix old syntax like deny from with modern Require not ip.

Quick checklist after activation

  • Open Wordfence Live Traffic again and check if attacker IPs now receive 403 responses.
  • Check cPanel to see whether index.php processes have decreased.
  • Monitor whether CPU starts dropping within the next few minutes.
  • Remove IP blocks that are no longer needed or that affect legitimate visitors.

When this is not enough

If your site receives frequent bot waves, .htaccess helps, but it does not replace a proper WAF or rate limiter. The long-term solution is to have a protection layer before the request reaches WordPress.

  • Keep the User-Agent shield active.
  • Monitor Wordfence Live Traffic regularly.
  • Add or remove /24 blocks only when confirmed by logs.
  • For frequent attacks, consider WAF/rate limiting at proxy or CDN level.