PHP opcache.revalidate_freq Explained: Configuration, Performance, and Best Practices
Introduction
The opcache.revalidate_freq directive determines how frequently PHP OPcache checks whether cached PHP scripts have changed on disk. It works together with opcache.validate_timestamps to balance application performance with code update detection.
A lower value allows code changes to become visible more quickly, while a higher value reduces filesystem checks and improves performance. Selecting the appropriate value depends on whether your environment prioritizes rapid development or maximum production efficiency.
This guide explains how opcache.revalidate_freq works, how to configure it, recommended values for different environments, and common troubleshooting scenarios.
Test Environment
What Is opcache.revalidate_freq?
When opcache.validate_timestamps is enabled, PHP periodically checks whether cached scripts have been modified.
The opcache.revalidate_freq directive specifies the minimum number of seconds between these checks.
Example:
opcache.revalidate_freq = 2
With this configuration, OPcache checks the file modification time at most once every 2 seconds.
How It Works
Consider a PHP file that has already been cached.
If the configured interval has not expired, OPcache skips the filesystem check and immediately uses the cached bytecode.
Check the Current Value
Run:
Example:
opcache.revalidate_freq => 2 => 2
Or create a PHP file:
Search for:
opcache.revalidate_freq
Locate the Active Configuration File
Run:
Many Linux distributions store OPcache settings in:
/etc/php.d/10-opcache.ini
Modify the configuration used by PHP-FPM rather than only the CLI configuration.
Change opcache.revalidate_freq
Open the OPcache configuration file.
Locate:
opcache.revalidate_freq = 2
Example:
opcache.revalidate_freq = 60
Save the file.
Restart PHP-FPM
Apply the changes.
Verify:
Expected output:
Active: active (running)
Verify the Configuration
Run:
The displayed value should match your configuration.
Development vs Production
#Development
Recommended configuration:
opcache.validate_timestamps = 1
opcache.revalidate_freq = 0
Setting revalidate_freq to 0 tells OPcache to check file modification times on every request. This ensures code changes become visible immediately without manually clearing the cache.
#Production
Recommended configuration:
opcache.validate_timestamps = 0
or
opcache.validate_timestamps = 1
opcache.revalidate_freq = 60
If timestamp validation is disabled, opcache.revalidate_freq has no effect.
If timestamp validation remains enabled, increasing the interval reduces filesystem checks and slightly improves performance.
Relationship with validate_timestamps
These directives are closely related.
Example:
opcache.validate_timestamps = 1
opcache.revalidate_freq = 10
In this configuration, OPcache checks for file changes at most once every ten seconds.
If:
opcache.validate_timestamps = 0
then:
opcache.revalidate_freq
is ignored because no timestamp validation occurs.
Recommended Values
These values provide a balance between rapid code updates and reduced filesystem overhead.
Common Issues
Code Changes Do Not Appear Immediately
If opcache.revalidate_freq is set to a large value, PHP may continue using cached bytecode until the next validation interval.
For example, with:
opcache.revalidate_freq = 60
changes may not become visible for up to one minute.
revalidate_freq Appears to Have No Effect
This usually happens because:
opcache.validate_timestamps = 0
When timestamp validation is disabled, OPcache never checks file modification times, regardless of the revalidate_freq value.
Frequent Filesystem Access
Setting:
opcache.revalidate_freq = 0
causes OPcache to check file timestamps on every request.
While useful during development, this introduces additional filesystem operations and is generally not recommended for production.
Best Practices
Use opcache.revalidate_freq = 0 for local development.
Use a small value (1–2 seconds) on shared development servers.
Use a larger interval or disable timestamp validation on production servers.
Coordinate OPcache settings with your deployment process.
Restart PHP-FPM or reset OPcache after deployment when automatic validation is disabled.
Conclusion
The opcache.revalidate_freq directive controls how frequently PHP OPcache checks whether cached PHP scripts have changed. It works only when opcache.validate_timestamps is enabled and helps balance fast code updates against filesystem overhead.
For development environments, checking for changes on every request or every few seconds provides a smoother workflow. For production systems, increasing the validation interval—or disabling timestamp validation entirely with a deployment process that refreshes OPcache—can improve performance while keeping application behavior predictable.
Explore More
› PHP opcache.max_accelerated_files Explained: Configuration, Performance, and Best Practices
› PHP opcache.validate_timestamps Explained: Configuration, Code Updates, and Best Practices
› PHP opcache.enable Explained: Configuration, Performance, and Best Practices
› PHP opcache.save_comments Explained: Configuration, Compatibility, and Best Practices