🚀 Ultra-fast web hosting from just $1/month!
HostPedia

OPcache

Performance
Definition

OPcache is a PHP performance feature that speeds up applications by storing precompiled script bytecode in shared memory, reducing repeated parsing and compilation on each request. By reusing cached opcode, it lowers CPU usage and improves response times for dynamic sites. It is commonly enabled as a PHP extension and tuned with memory, validation, and revalidation settings.

How It Works

When a PHP request arrives, PHP normally reads the script, tokenizes it, parses it, and compiles it into opcode (bytecode) before executing. OPcache intercepts this flow by caching the compiled opcode in shared memory. Subsequent requests can execute the cached opcode directly, avoiding the compilation step and reducing per-request CPU overhead.

OPcache behavior is controlled through configuration directives such as cache memory size, the maximum number of cached scripts, and how often PHP checks for file changes. In production, you typically want stable caching with controlled revalidation (or manual cache resets during deployments). In development, more frequent timestamp checks help ensure code changes are picked up quickly, at the cost of some performance.

Why It Matters for Web Hosting

For hosting comparisons, OPcache can be the difference between a PHP site that feels sluggish under traffic and one that remains responsive. Plans that include OPcache (and allow sensible tuning) generally deliver better performance per CPU core, especially for WordPress, Laravel, and other PHP-heavy workloads. When evaluating providers, confirm OPcache is enabled, has adequate memory, and is compatible with your deployment workflow.

Common Use Cases

  • Speeding up PHP CMS sites such as WordPress, Joomla, and Drupal
  • Improving performance of PHP frameworks and apps (Laravel, Symfony) with many included files
  • Reducing CPU load on shared hosting accounts with frequent dynamic requests
  • Stabilizing response times during traffic spikes by cutting compilation overhead
  • Pairing with PHP-FPM and Nginx or Apache for higher throughput on VPS or dedicated servers

OPcache vs APCu

OPcache caches compiled PHP opcode, targeting the compilation step, while APCu caches user data (application objects, arrays, computed results) in memory. They solve different problems and are often used together: OPcache accelerates code execution startup, and APCu can reduce repeated database queries or expensive computations. In hosting plans, OPcache is usually the baseline performance feature, while APCu is an optional enhancement depending on your application and access to PHP settings.