keepcalculator

06 Numbers and Powers

How to Improve WordPress PHP Performance

Card No. 06·71499 · Updated · Standard formula, shown below

Slow WordPress sites frustrate visitors and hurt your search rankings. This guide walks through practical, code-level improvements to make your PHP execution faster, reduce server load, and improve Time to First Byte (TTFB). You’ll learn to identify bottlenecks, apply caching, optimize database queries, and configure your server for peak PHP performance.

What You’ll Need

  • Access to your WordPress admin dashboard
  • FTP or file manager access to your site’s files
  • Access to your hosting control panel (cPanel, Plesk, or similar)
  • Basic understanding of PHP and WordPress structure
  • A staging site to test changes before going live (recommended)

Step-by-Step

  1. Measure your current PHP performance. Before changing anything, establish a baseline. Use a tool like Query Monitor or a simple microtime script to record page generation time. Also check your server’s PHP error log for warnings and notices that indicate inefficient code.
  2. Update PHP to the latest supported version. PHP 8.x is significantly faster than PHP 5.x or 7.x. In your hosting control panel, look for “Select PHP Version” or “PHP Settings.” Choose the newest stable version (e.g., 8.2 or 8.3) and test your site thoroughly. Most modern themes and plugins are compatible, but check for deprecated function warnings.
  3. Enable a PHP opcode cache. OPcache stores compiled PHP scripts in memory, eliminating the need to recompile on every request. In your PHP settings, enable OPcache and set realistic values: opcache.memory_consumption=128, opcache.max_accelerated_files=10000, and opcache.revalidate_freq=60. This alone can cut PHP execution time by 30-50%.
  4. Install a caching plugin. A plugin like WP Super Cache or W3 Total Cache generates static HTML files of your pages and serves them to most visitors, bypassing PHP entirely. Configure page caching, object caching (if using a persistent backend like Redis or Memcached), and opcode caching. Start with page caching; it’s the most impactful.
  5. Optimize your database. Over time, WordPress databases accumulate post revisions, spam comments, and transient options. Use a plugin like WP-Optimize or run manual SQL queries to clean up. Also, ensure your database tables use the InnoDB engine, which handles concurrent reads better than MyISAM.
  6. Minify and combine CSS/JS files. While not strictly PHP, reducing the number of HTTP requests and file sizes decreases the time PHP spends generating the page. Use Autoptimize or W3 Total Cache to minify and combine assets. Be careful with JavaScript: combine only if your site doesn’t rely on load order.
  7. Audit your plugins and theme. Deactivate all plugins and switch to a default theme (like Twenty Twenty-Four). Measure performance. Reactivate each plugin one by one, testing after each. This identifies resource-heavy plugins. Replace those with lighter alternatives or find optimized settings.
  8. Use a content delivery network (CDN). A CDN serves static assets (images, CSS, JS) from edge servers close to the user, reducing the load on your origin server. This frees up PHP to handle dynamic requests faster. Cloudflare’s free tier is a good starting point.
  9. Implement object caching. For dynamic sites, object caching stores database query results in memory. If your host supports Redis or Memcached, install a plugin like Redis Object Cache and configure it. This dramatically reduces database load, especially on high-traffic sites.
  10. Optimize your PHP code. In your theme’s functions.php file, avoid expensive queries inside loops. Use wp_query with no_found_rows when you don’t need pagination, and use pre_get_posts to modify queries before they run. Also, use transients to cache expensive function results.
  11. Enable compression and keep-alive. In your server configuration (Apache .htaccess or Nginx config), enable gzip or Brotli compression for text files. Also, enable Keep-Alive to reuse connections. These reduce bandwidth and latency, making PHP responses feel faster.
  12. Monitor and adjust. After each change, re-measure your performance. Use a tool like GTmetrix or Pingdom to see TTFB and overall load time. Keep an eye on your server’s CPU and memory usage. Adjust OPcache and caching settings based on your traffic patterns.

Common Mistakes

  • Enabling too many caching layers. Having both page caching and object caching without proper configuration can cause stale content or conflicts. Test each layer individually.
  • Ignoring PHP error logs. Notices and warnings often indicate inefficient code. Fix them, don’t suppress them.
  • Using a heavy page builder. Page builders like Elementor or Divi add significant PHP overhead. If possible, use a lighter theme or optimize the page builder’s settings.
  • Not testing on a staging site. Making changes directly on a live site can break functionality. Always test first.
  • Over-optimizing with too many plugins. Each plugin adds PHP execution time. Use only what you need.

Tips

  • Use a performance plugin that provides a comprehensive dashboard, like LiteSpeed Cache if you’re on LiteSpeed server, or WP Rocket (premium) for simplicity.
  • Consider using a managed WordPress host that handles PHP optimization, caching, and CDN automatically.
  • Schedule regular database cleanups (weekly or monthly) to keep things lean.
  • Use a plugin like Query Monitor to see exactly how many queries each page runs and how long they take.
  • Keep your WordPress core, themes, and plugins updated to benefit from performance improvements.

Troubleshooting

  • Site breaks after updating PHP. Revert to the previous PHP version temporarily. Check for deprecated function errors in the logs. Update your theme and plugins to versions compatible with the new PHP.
  • Blank white screen after enabling OPcache. This usually means OPcache is misconfigured. Set opcache.enable=1 and opcache.validate_timestamps=1 (in development) to ensure files are re-read when changed. Clear the cache via your control panel.
  • Caching plugin causes outdated content. Clear the cache manually and check if the plugin has an option to exclude dynamic pages (like cart or checkout) from caching. Ensure the cache TTL is appropriate.
  • Database optimization makes site slower. If you ran manual SQL and removed too much, you might have deleted active transients. Restore from a backup. Use a plugin that handles this safely.
  • Object caching not working. Check if your server actually has Redis or Memcached installed. Use a plugin that shows connection status. If not available, stick with page caching.

Frequently Asked Questions

Do I need a caching plugin if I have a CDN?

Yes, they serve different purposes. A CDN caches static files at the edge, while a caching plugin generates static HTML of your pages to reduce PHP execution. Both are beneficial.

What is a good TTFB for WordPress?

Under 200ms is excellent, under 500ms is good, and above 1 second is poor. TTFB is influenced by server response time, which PHP optimization directly improves.

Will these changes affect my SEO?

Yes, positively. Faster page load times are a ranking factor and improve user experience, reducing bounce rates.

Can I do all this without a developer?

Most steps are plugin-based and require no coding. The PHP code optimization step requires basic coding knowledge, but many hosts offer managed WordPress that handles most of this automatically.

How often should I clear my cache?

You don’t need to clear it manually unless you’ve made changes to your site. Caching plugins automatically expire and rebuild pages based on your settings.

Is it safe to delete WordPress post revisions?

Yes, but keep at least the latest revision. Use a plugin that allows you to set a limit, like 5 revisions per post, to avoid losing history entirely.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →