PHP OPcache Management and Optimization
What is OPcache?
OPcache is a PHP extension that improves performance by storing precompiled script bytecode in shared memory, eliminating the need to load and parse PHP scripts on every request.
OPcache Benefits
- Faster PHP execution: 2-10x performance improvement
- Reduced server load: Less CPU and memory usage
- Better scalability: Handle more concurrent users
- Improved response times: Faster page generation
ZiziCache OPcache Features
Statistics and Monitoring
View detailed OPcache statistics in System � OPcache:
- Memory usage: Total, used, free, and wasted memory
- Hit rates: Cache effectiveness percentages
- Cached scripts: Number of cached PHP files
- Version information: OPcache and PHP versions
- Host details: Server hostname and software
Domain Memory Usage Analysis
- WordPress Core: Memory used by WordPress core files
- Themes: Active theme memory consumption
- Plugins: Per-plugin memory usage breakdown
- Total footprint: Overall OPcache memory usage
OPcache Management
Manual Cache Flush
- Flush OPcache from admin dashboard
- Clear cache after plugin updates
- Reset cache after code changes
Automatic Flush Features
- WordPress updates: Auto-flush after core updates
- Plugin activation: Clear cache when plugins change
- Theme switches: Flush when changing themes
WP-CLI Integration
Available Commands
# View OPcache statistics wp zizi-cache opcache stats # Flush OPcache wp zizi-cache opcache flush
Command Examples
# Check OPcache status wp zizi-cache opcache stats # Clear OPcache after deployment wp zizi-cache opcache flush
REST API Integration
Available Endpoints
- GET /opcache/stats: Retrieve OPcache statistics
- POST /opcache/flush: Flush OPcache
- GET /opcache/domain-usage: Get domain memory usage
Configuration and Security
Security Checks
- Extension availability validation
- Function existence verification
- API restriction compliance
- Permission-based access control
Error Handling
- Graceful degradation when OPcache unavailable
- Detailed error logging
- Fallback for restricted environments
Performance Recommendations
Optimal OPcache Settings
- opcache.memory_consumption: 128MB+ for WordPress sites
- opcache.max_accelerated_files: 10000+ for large sites
- opcache.revalidate_freq: 2-60 seconds depending on environment
- opcache.validate_timestamps: 0 for production (with manual flush)
Monitoring Best Practices
- Check hit rates regularly (should be 95%+)
- Monitor memory usage to prevent exhaustion
- Watch for high wasted memory percentages
- Track per-plugin memory consumption
Troubleshooting
Common Issues
- Low hit rates: Increase memory or max_accelerated_files
- Memory exhaustion: Increase opcache.memory_consumption
- Frequent restarts: Check for memory limits or file limits
- High wasted memory: Flush cache or adjust settings
Diagnostic Steps
- Check OPcache statistics in admin panel
- Review error logs for OPcache messages
- Verify OPcache configuration settings
- Test manual flush functionality
- Monitor performance before and after changes