PHP 8 interview question · Most asked

What is OPcache and how should it be configured in production?

Summary

OPcache stores compiled opcodes in shared memory so PHP doesn't re-parse scripts on every request. It's the single most important PHP performance setting.

Longer Answer

Recommended production settings: opcache.enable=1, enough opcache.memory_consumption (e.g., 256M) and opcache.max_accelerated_files for your file count, and opcache.validate_timestamps=0 so PHP never stats files, which means you must reset OPcache (reload FPM) on deploy. opcache.interned_strings_buffer saves memory for repeated strings.

Code Example

opcache.enable=1
opcache.memory_consumption=256
opcache.interned_strings_buffer=16
opcache.max_accelerated_files=20000
opcache.validate_timestamps=0

Key Points

  • Caches compiled opcodes in shared memory
  • validate_timestamps=0 in prod + reload on deploy
  • Size memory and max files for your codebase
  • Monitor hit rate with opcache_get_status()

More most-asked PHP 8 questions

← All PHP 8 questions