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=0in 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
- What are the most important features introduced in PHP 8.0?
- What happens to an HTTP request in a PHP-FPM application, and what does 'shared nothing' mean?
- How should passwords be stored in PHP?
- What are named arguments and what are their benefits and risks?
- What is constructor property promotion?
- How does `match` differ from `switch`?
- What are union types in PHP 8 and how do you use them?
- What are enums in PHP 8.1? Explain pure vs backed enums.