Reduce TTFB on cheap hosting (object cache & OPcache)
Reduce TTFB on Cheap Hosting (Object Cache & OPcache)
Time To First Byte (TTFB) is a critical performance metric for WordPress sites. On cheap hosting, slow TTFB can frustrate visitors and harm SEO. The good news: you can significantly reduce TTFB by enabling OPcache and object caching, cleaning up your database, and using a CDN. This guide walks you through practical steps to speed up your WordPress site without expensive hosting upgrades.
Quick Fix
- Enable PHP OPcache on your server.
- Activate an object caching plugin like Redis or Memcached.
- Clean up your WordPress database to remove overhead.
- Integrate a CDN to serve static assets closer to users.
Why This Happens
Cheap hosting often uses shared resources and limited server configurations, resulting in slower PHP execution and database queries. Without caching, every page load triggers PHP scripts and database calls from scratch, increasing TTFB. OPcache stores precompiled PHP bytecode in memory, reducing script load times. Object caching stores database query results in memory, cutting down repeated queries. Cleaning the database removes bloat that slows queries. A CDN reduces latency by serving assets from edge servers near visitors.
Step-by-step
1. Enable OPcache
OPcache is a PHP extension that caches compiled script bytecode. Many cheap hosts support it but may not enable it by default.
- Check if OPcache is enabled by creating a
phpinfo.php
file in your WordPress root with this content:<?php phpinfo(); ?>
- Access
yourdomain.com/phpinfo.php
and search for “OPcache”. If enabled, you’ll see its configuration. - If not enabled, enable it via your hosting control panel or by adding this to your
php.ini
or.user.ini
file:opcache.enable=1 opcache.memory_consumption=128 opcache.interned_strings_buffer=8 opcache.max_accelerated_files=4000 opcache.revalidate_freq=60 opcache.fast_shutdown=1
- Restart PHP or your web server if possible.
2. Enable Object Cache
Object caching stores database query results in memory, reducing repeated queries and lowering TTFB.
- Check if your host supports Redis or Memcached. You can ask support or check documentation.
- Install a WordPress plugin for object caching, for example:
- Redis:
Redis Object Cache
plugin - Memcached:
Memcached Redux
orW3 Total Cache
- Redis:
- Configure the plugin to connect to your Redis or Memcached server. Usually, this is
127.0.0.1
and default ports. - Verify caching is active via the plugin’s status page.
3. Clean Up Your Database
A bloated database slows queries, increasing TTFB. Cleaning removes overhead, spam, revisions, and transient options.
- Backup your database before making changes.
- Install a plugin like
WP-Optimize
orAdvanced Database Cleaner
. - Run database optimization:
- Remove post revisions
- Delete spam and trashed comments
- Clear expired transients
- Optimize database tables
- Schedule regular cleanups to maintain performance.
4. Use a CDN
A Content Delivery Network (CDN) reduces latency by serving static files (images, CSS, JS) from servers closer to visitors.
- Choose a CDN provider (Cloudflare, BunnyCDN, StackPath, etc.).
- Create an account and configure your domain.
- Change your DNS nameservers to point to the CDN (if using Cloudflare) or configure your CDN to pull from your origin server.
- Install a plugin like
Cloudflare
orCDN Enabler
to integrate the CDN with WordPress. - Verify static assets load from the CDN URL.
Works on
Environment | Notes |
---|---|
Apache | Supports OPcache and object cache; .htaccess may be used for CDN rewrites. |
Nginx | Fully compatible with OPcache and object cache; CDN integration via proxy or DNS. |
LiteSpeed | Supports OPcache and object cache; LiteSpeed Cache plugin can help. |
cPanel | Enable OPcache via MultiPHP INI Editor; Redis/Memcached often available. |
Plesk | Enable OPcache via PHP settings; Redis/Memcached extensions can be installed. |
FAQ
- Q: How do I know if OPcache is working?
- A: Use a
phpinfo()
page or a plugin like Query Monitor to check if OPcache is enabled and caching scripts. - Q: Can I enable object caching without Redis or Memcached?
- A: Yes, but it’s less efficient. Some plugins offer file-based caching, but memory-based caches like Redis/Memcached are faster.
- Q: Will enabling OPcache and object cache fix all performance issues?
- A: They significantly reduce TTFB but don’t replace good hosting or optimized themes/plugins. Combine with database cleanup and CDN for best results.
- Q: Is it safe to clean my database with plugins?
- A: Yes, if you backup first. Use reputable plugins and avoid deleting data you might need.
- Q: Does using a CDN increase my hosting costs?
- A: Most CDNs have free tiers or low-cost plans. They