🐘 PHP Advanced

What is OPcache in PHP?

Why Interviewers Ask This

This is a differentiating question used for senior and lead roles. Interviewers want to see if you can explain not just what happens, but why — and what the trade-offs are in different approaches.

Answer

OPcache is a PHP bytecode caching extension bundled with PHP since 5.5. Normally, PHP parses and compiles every source file into opcodes (bytecode) on every request. OPcache stores compiled opcodes in shared memory, so subsequent requests reuse the precompiled bytecode, skipping the parse and compile steps. This significantly reduces CPU usage and request response times — typically 50-70% performance improvement for web applications. Enable in php.ini: opcache.enable=1. Key settings: opcache.memory_consumption (amount of shared memory), opcache.max_accelerated_files (how many files to cache), opcache.revalidate_freq (how often to check if source changed). In production, set opcache.validate_timestamps=0 to disable file change checks entirely for maximum performance.

Pro Tip

Back up your answer with a specific project or situation. Saying 'In my last PHP project, I used this when...' immediately makes your answer more credible and memorable.