1. Offload the Application Layer (The “Static” Strategy)
The most effective way to save your server is to ensure PHP never runs.
- Full Page Caching at the Edge: Use Cloudflare APO or Super Page Cache. By serving the HTML directly from the CDN’s edge, your server stays at 0% CPU for 95% of your traffic.
- Stale While Revalidate: Configure your cache headers so that the CDN serves a “stale” version of the page while it fetches the updated one in the background. This prevents the “Cache Stampede” effect where thousands of users hit the origin simultaneously when a cache expires.
2. Decouple the Database
On high-traffic sites, the database is usually the first thing to fail.
- Persistent Object Caching (Redis): This is mandatory. Without it, your metadata lookups will lock the MySQL tables.
- Read/Write Splitting: For massive scale, move your database to a managed service like AWS RDS or DigitalOcean Managed DB. This allows you to scale the database vertically without touching the web server.
3. PHP-FPM and Web Server Tuning
If your server is choking, your worker pool is likely misconfigured.
- Process Management: Switch from
pm = dynamictopm = staticif you have a dedicated server. This eliminates the overhead of spawning new PHP processes under load. - Max Children Calculation: Calculate your
pm.max_childrenbased on available RAM.Formula:(Total RAM - OS/DB Reserved) / Average PHP Process Size = Max Children - Nginx Microcaching: Implement a 1-second microcache for dynamic pages. Even a 1-second cache can prevent a server crash during a massive viral surge.
4. Asset Offloading
Every image or JS file served by your server is a thread that could be used for a PHP process.
- External CDN: Move your
/uploads/folder to AWS S3 or Google Cloud Storage. Use a plugin like WP Offload Media. - Hotlink Protection: Ensure other sites aren’t “stealing” your bandwidth and server resources by embedding your images on their high-traffic pages.
5. Managing the “Heartbeat” and Cron
- Heartbeat API: The WordPress Heartbeat (
admin-ajax.php) sends pulses every 15–60 seconds while the dashboard is open. On a multi-author site, this can kill the server. Use a plugin or code snippet to limit it to 2 minutes or disable it entirely. - System Cron: As previously mentioned, move
wp-cronto a system-level task so it doesn’t trigger on user visits.