Zend OPcache works automatically once enabled and properly configured. You do not need to add anything to your PHP scripts, HTML pages, or application code.
OPcache operates transparently at the PHP engine level.
How it works
When PHP executes a script:
- PHP checks whether its compiled version is already in OPcache.
- If it is, PHP executes the cached opcodes.
- If it isn’t, PHP compiles the source and stores the resulting opcodes in shared memory.
- Subsequent requests reuse those compiled opcodes.
This happens automatically.
Configuration worth checking
In your PHP configuration (php.ini), these are the important settings:
opcache.enable=1
opcache.enable_cli=0
opcache.memory_consumption=128
opcache.interned_strings_buffer=16
opcache.max_accelerated_files=10000
opcache.validate_timestamps=1
opcache.revalidate_freq=2
These are reasonable starting values, not mandatory settings. In particular:
opcache.enable: Enables OPcache for web requests.opcache.memory_consumption: Memory allocated for cached opcodes, in MB.opcache.interned_strings_buffer: Memory for interned strings.opcache.max_accelerated_files: Maximum number of cached script entries.opcache.validate_timestamps: Checks whether PHP source files have changed.opcache.revalidate_freq: How frequently timestamp checks occur, in seconds.
With validate_timestamps=1 and revalidate_freq=2, changes to PHP files should generally be recognized within a couple of seconds.
If you disable timestamp validation for production performance, remember that you’ll need to reset OPcache or restart the PHP handler when deploying changed scripts.
How to verify OPcache is working
Create a temporary PHP file:
<?php
echo '<pre>';
print_r(opcache_get_status(false));
echo '</pre>';
Look for:
[opcache_enabled] => 1
You can also inspect:
opcache_statisticsnum_cached_scriptshitsmissesmemory_usageopcache_hit_rate
These tell you whether scripts are being cached and how effectively OPcache is being used.
Security note: Don’t leave a publicly accessible diagnostic script on your website. It exposes server configuration information. Delete it after testing.



