PHP opcache.validate_timestamps Explained: Configuration, Code Updates, and Best Practices
Introduction
The opcache.validate_timestamps directive determines whether PHP OPcache checks if a cached PHP script has changed on disk before reusing its compiled bytecode.
When enabled, OPcache periodically verifies file modification times and recompiles scripts if changes are detected. When disabled, cached bytecode is always reused until the OPcache is manually reset or the PHP process is restarted.
Choosing the correct setting depends on your deployment workflow. Development environments typically require automatic change detection, while production servers often prioritize maximum performance.
This guide explains how opcache.validate_timestamps works, how to configure it, and the recommended settings for different environments.
Test Environment
What Is opcache.validate_timestamps?
OPcache stores compiled PHP bytecode in shared memory to avoid recompiling scripts on every request.
The opcache.validate_timestamps directive determines whether PHP checks if the original source file has changed.
Enable automatic checking:
opcache.validate_timestamps = 1
Disable automatic checking:
opcache.validate_timestamps = 0
When the value is 0, PHP assumes cached scripts never change until the cache is explicitly cleared.
How It Works
With timestamp validation enabled:
With timestamp validation disabled:
No filesystem check occurs before executing the cached script.
Check the Current Value
Run:
Example output:
opcache.validate_timestamps => On => On
Or use:
Search for:
opcache.validate_timestamps
Locate the Active Configuration File
Run:
php --ini
Many Linux distributions store OPcache settings in a separate file such as:
/etc/php.d/10-opcache.ini
Always edit the configuration used by PHP-FPM.
Change opcache.validate_timestamps
Open the OPcache configuration file.
Enable automatic validation:
opcache.validate_timestamps = 1
Disable automatic validation:
opcache.validate_timestamps = 0
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
Developers frequently modify PHP files. Automatic timestamp validation ensures code changes are detected without manually clearing the OPcache.
#Production
Recommended configuration:
opcache.validate_timestamps = 0
Production code is typically updated through controlled deployment processes. Disabling timestamp checks eliminates unnecessary filesystem lookups and provides slightly better performance.
After each deployment, clear the OPcache or restart PHP-FPM so the new code is cached.
Relationship with revalidate_freq
These directives work together.
Example:
opcache.validate_timestamps = 1
opcache.revalidate_freq = 2
With this configuration, OPcache checks file modification times at most once every two seconds.
If opcache.validate_timestamps is set to 0, the opcache.revalidate_freq setting is ignored.
Common Issues
Code Changes Do Not Appear
Possible causes include:
opcache.validate_timestamps is disabled.
OPcache has not been reset after deployment.
The application uses multiple PHP-FPM pools with different configurations.
Restarting PHP-FPM or resetting the OPcache usually resolves the issue.
Frequent Filesystem Checks
Development environments benefit from automatic change detection, but checking timestamps on every request introduces a small amount of filesystem overhead.
For production servers with stable application code, disabling timestamp validation can reduce this overhead.
Deployment Uses Old Code
If timestamp validation is disabled, deploying new PHP files alone is not enough. The cached bytecode remains in memory until OPcache is reset or PHP-FPM is restarted.
Deployment scripts should include an OPcache reset step or a controlled PHP-FPM reload.
Best Practices
Enable timestamp validation during development.
Disable timestamp validation on production servers with automated deployments.
Restart PHP-FPM or reset OPcache after deploying new code when validation is disabled.
Configure opcache.revalidate_freq appropriately for your environment.
Verify the active settings using phpinfo() or php -i.
Conclusion
The opcache.validate_timestamps directive determines whether PHP checks for changes to cached PHP scripts before executing them. Enabling it provides automatic code update detection, making it ideal for development environments. Disabling it removes periodic filesystem checks and can slightly improve performance on production servers, provided your deployment process refreshes the OPcache after each release.
Understanding how this directive interacts with opcache.revalidate_freq is essential for balancing performance and deployment reliability.
Explore More
› PHP opcache.max_accelerated_files Explained: Configuration, Performance, and Best Practices
› PHP opcache.revalidate_freq Explained: Configuration, Performance, and Best Practices
› PHP opcache.enable Explained: Configuration, Performance, and Best Practices
› PHP opcache.save_comments Explained: Configuration, Compatibility, and Best Practices