PHP OPcache Management and Optimization
What is OPcache?
OPcache is a PHP extension that stores precompiled script bytecode in shared memory, reducing parse and compile overhead on each request.
ZiziCache OPcache features
Statistics and monitoring
- Memory usage: total, used, free, wasted
- Cache efficiency: hit rate, hits, misses, cached keys
- Cached scripts: number of cached PHP files
- System details: OPcache/PHP versions, host name, server software
- Interned strings: buffer size and usage
Domain usage breakdown
- WordPress core: memory used by core files
- Theme: active theme memory consumption
- Plugins: per-plugin memory usage (best-effort based on script paths)
Note: The breakdown is derived from OPcache script paths and can be approximate in multi-site or multi-domain environments.
OPcache management
Manual flush
- Flush OPcache from ZiziCache OPcache.
- Use after deployments or when PHP files change.
Automatic flush after updates (optional)
- When enabled, ZiziCache flushes OPcache after WordPress core, plugin, or theme updates.
WP-CLI
# View OPcache statistics wp zizi-cache opcache stats # Flush OPcache wp zizi-cache opcache flush # Alternative flush commands (same effect) wp zizi-cache opcache-flush wp zizi-cache opcache/flush
REST API
- GET /wp-json/zizi-cache/v1/opcache/stats
- POST /wp-json/zizi-cache/v1/opcache/flush
- GET /wp-json/zizi-cache/v1/opcache/domain-usage
Limits and prerequisites
- Requires the Zend OPcache PHP extension.
- Flush uses
opcache_reset()and can be blocked byopcache.restrict_api.
Redis Object Cache (optional)
ZiziCache can manage Redis object cache by installing the object-cache.php drop-in and writing Redis constants to wp-config.php when enabled in the UI.
- Connections: TCP or Unix socket.
- Authentication: Redis 6+ ACL (username + password) or password-only.
- Library: Predis is bundled with the plugin.
- Status/flush: Available via REST endpoints and the admin UI.
WP-CLI
# Flush Redis (uses wp_cache_flush under the hood) wp zizi-cache redis-flush # Flush object cache (backend-agnostic: Redis or Memcached) wp zizi-cache object-cache-flush
REST API
- GET /wp-json/zizi-cache/v1/redis-status
- POST /wp-json/zizi-cache/v1/redis-flush
Memcached Object Cache (optional)
ZiziCache supports both PHP extensions (memcached and legacy memcache) and automatically selects the available backend.
- Drop-in: installs
object-cache.phpfrom a backend-specific template. - Servers: configurable host:port list or Unix socket.
- Optional security: SASL credentials and timeouts are written to
wp-config.phpwhen configured. - Connection testing: rate-limited and validated to avoid unsafe hosts and ports.
WP-CLI
# Flush object cache (backend-agnostic: Redis or Memcached) wp zizi-cache object-cache-flush
REST API
- GET /wp-json/zizi-cache/v1/memcached-status
- POST /wp-json/zizi-cache/v1/memcached-test
- POST /wp-json/zizi-cache/v1/memcached-flush
- GET /wp-json/zizi-cache/v1/memcached-environment
Redis vs Memcached
Only one object cache backend can be active at a time. Enabling Redis disables Memcached and vice versa.