Controlling the WordPress Heartbeat API
The WordPress Heartbeat API allows your browser to communicate with the server in real-time when you are logged in. It's responsible for:
- Auto-saving posts.
- Showing you when other authors are editing a post.
- Real-time dashboard notifications.
The Problem
By default, the Heartbeat pulses every 15-60 seconds. If you have multiple tabs open or multiple authors editing, this can flood your server with POST requests, causing high CPU usage.
Step 1: Diagnosing the Issue
If your host complains about "high CPU usage" or "admin-ajax.php" abuse, the Heartbeat is usually the suspect.
Step 2: Controlling Heartbeat with WP Rocket
- Go to Settings > WP Rocket > Heartbeat.
- Control Heartbeat: Enable.
- Behavior in backend: Reduce activity.
- Behavior in post editor: Reduce activity (or leave as is if you rely heavily on auto-save).
- Behavior in frontend: Disable (usually not needed for visitors).
Step 3: Controlling Heartbeat with a Free Plugin
If you don't use WP Rocket, use Heartbeat Control by WP Rocket (free standalone plugin).
- Install Heartbeat Control.
- Go to Settings > Heartbeat Control.
- Set Frontend to Disable.
- Set Post Editor to Modify Frequency -> 60s (instead of 15s).
- Set Dashboard to Disable or 60s.
Conclusion
Taming the Heartbeat API is a quick fix that can drastically lower server load, especially for sites with multiple admins or editors.
Next, we will dive into Advanced Database Optimization, adding indexes to speed up queries.