Shahid Malla

Redis and OPcache for WHMCS: Complete Caching Performance Guide

Shahid Malla Shahid Malla February 9, 2026 14 min read
Redis and OPcache for WHMCS: Complete Caching Performance Guide

Caching is one of the most effective ways to improve WHMCS performance. This guide covers implementing Redis for sessions and object caching, plus optimizing OPcache for PHP opcode caching, resulting in significantly faster page loads.

Performance Improvements

  • 40-60% faster page load times
  • Reduced database load by 30-50%
  • Faster session handling
  • Lower memory usage per request
  • Better scalability under load

Understanding Caching Types

Types of Caching for WHMCS

Cache Type What It Caches Primary Benefit
OPcache Compiled PHP bytecode Eliminates PHP parsing overhead
Redis Sessions User session data Faster session read/write
Redis Object Query results, computed data Reduces database queries
Template Cache Compiled Smarty templates Faster template rendering

OPcache Configuration

What is OPcache?

OPcache stores precompiled PHP bytecode in shared memory, eliminating the need to parse and compile PHP files on each request. This can reduce PHP execution time by 2-3x.

Verify OPcache is Enabled

Check your PHP configuration:

  • Create phpinfo file and check OPcache section
  • Look for "Zend OPcache" in loaded extensions
  • Check "opcache.enable" is set to 1

Recommended OPcache Settings

Setting Recommended Value Purpose
opcache.enable 1 Enable OPcache
opcache.memory_consumption 256 Memory for cached scripts (MB)
opcache.interned_strings_buffer 16 Memory for strings (MB)
opcache.max_accelerated_files 10000 Max cached scripts
opcache.validate_timestamps 0 (prod) / 1 (dev) Check for file changes
opcache.revalidate_freq 60 Seconds between checks
opcache.save_comments 1 Preserve doc comments

Production vs Development

  • Production: Set validate_timestamps to 0 for max performance
  • Development: Set validate_timestamps to 1 to see code changes
  • After WHMCS updates, restart PHP-FPM to clear cache

Redis Installation

Install Redis Server

On Ubuntu/Debian:

  • Update package manager
  • Install redis-server package
  • Enable and start redis service
  • Verify with redis-cli ping command

On CentOS/RHEL:

  • Enable EPEL repository
  • Install redis package
  • Enable and start service

Install PHP Redis Extension

The PHP Redis extension is required for WHMCS to communicate with Redis:

  • Ubuntu/Debian: php-redis package
  • CentOS: php-pecl-redis package
  • Restart PHP-FPM after installation
  • Verify with phpinfo or php -m | grep redis

Redis Security

  • Bind to localhost only (default)
  • Set requirepass for authentication
  • Use firewall to block external access
  • Consider separate Redis instance for WHMCS

Redis Session Storage

Why Redis for Sessions?

  • Faster than file-based sessions
  • Works across multiple web servers
  • Automatic expiration handling
  • Reduces disk I/O

WHMCS Session Configuration

Configure Redis sessions in configuration.php:

  • Set session handler to Redis
  • Provide Redis connection details
  • Specify database number (0-15)
  • Set timeout value

Testing Session Storage

  1. Log into WHMCS client area
  2. Use redis-cli to verify session keys exist
  3. Check session prefix matches configuration
  4. Verify logout clears session

Redis Object Caching

What Can Be Cached?

  • Database query results
  • Configuration settings
  • Product information
  • Computed values
  • API responses

WHMCS Built-in Caching

WHMCS has a built-in caching system that can use Redis:

  • Configure in configuration.php
  • Set cache type to "redis"
  • Provide connection parameters
  • Set appropriate TTL values

Cache Warming

For optimal performance, warm the cache after clearing:

  • Visit main pages to populate cache
  • Use cron to pre-populate common data
  • Consider warming after WHMCS updates

Monitoring Cache Performance

OPcache Monitoring

  • Use opcache-gui or similar tools
  • Monitor memory usage
  • Check hit rate (should be 95%+)
  • Watch for cache full warnings

Redis Monitoring

  • redis-cli INFO command
  • Monitor memory usage
  • Check hit/miss ratio
  • Watch connection count

Key Metrics to Track

Metric Target Concern If
OPcache Hit Rate 95%+ Below 90%
Redis Memory Below max Near limit
Redis Connections Stable Growing constantly
Cache Evictions Minimal Frequent

Troubleshooting Common Issues

Sessions Not Working

  • Verify PHP Redis extension is loaded
  • Check Redis is running
  • Verify connection parameters
  • Check Redis logs for errors
  • Test with redis-cli connectivity

Cache Not Updating

  • Check OPcache validate_timestamps setting
  • Restart PHP-FPM to clear OPcache
  • Clear template cache in WHMCS admin
  • Flush Redis if needed

Memory Issues

  • Increase OPcache memory allocation
  • Set Redis maxmemory policy
  • Monitor for memory leaks
  • Consider separate Redis instances

Performance Not Improved

  • Verify caching is actually active
  • Check cache hit rates
  • Bottleneck may be elsewhere (database, network)
  • Profile with proper tools

Advanced Configuration

Redis Clustering

For high-availability setups:

  • Redis Sentinel for failover
  • Redis Cluster for scaling
  • Consider managed Redis services

Separate Redis Databases

  • Database 0: Sessions
  • Database 1: Object cache
  • Database 2: Other application data
  • Allows selective flushing

JIT Compilation (PHP 8+)

PHP 8 includes JIT which can provide additional performance beyond OPcache:

  • Requires OPcache to be enabled
  • Set opcache.jit_buffer_size
  • Configure opcache.jit setting
  • Benefits vary by workload

Performance Testing

Before and After Benchmarking

  1. Measure baseline page load times
  2. Implement caching changes
  3. Re-measure same pages
  4. Calculate improvement percentage

Tools for Testing

  • Apache Bench (ab) for load testing
  • GTmetrix for page speed analysis
  • New Relic for detailed profiling
  • Browser DevTools for timing

Caching Checklist

  • OPcache enabled and configured
  • OPcache memory adequate (256MB+)
  • Redis installed and running
  • PHP Redis extension installed
  • Redis session storage configured
  • Redis secured (password, localhost only)
  • Object caching configured
  • Monitoring in place
  • Performance tested before/after
  • Documentation updated

Conclusion

Implementing proper caching with Redis and OPcache is one of the most impactful performance optimizations for WHMCS. Redis provides fast session storage and object caching while OPcache eliminates PHP compilation overhead. Together, they can reduce page load times by 40-60% and significantly improve scalability.

Need Caching Setup Help?

I configure and optimize Redis caching and OPcache for WHMCS installations. Get maximum performance from your hosting platform.

Optimize My WHMCS
Share this article:
Shahid Malla

About Shahid Malla

Expert

Full Stack Developer with 10+ years of experience in WHMCS development, WordPress, and server management. Trusted by 600+ clients worldwide for hosting automation and custom solutions.