PHP opcache.revalidate_freq Explained: Configuration, Performance, and Best Practices

Published: 2026-07-08
Google AdSense 广告位 (待申请通过后开启)

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

Operating System : AlmaLinux 10
PHP Version      : PHP 8.3
Web Server       : Nginx
PHP-FPM          : Enabled
Architecture     : x86_64
Last Tested      : July 2026

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.

Request
    │
    ▼
OPcache
    │
    ▼
Has revalidate_freq expired?
    │
 ┌──┴──────────┐
 │             │
Yes           No
 │             │
 ▼             ▼
Check File   Use Cached
Timestamp    Bytecode
 │
 ▼
Changed?
 │
 ├── Yes → Recompile Script
 └── No  → Continue Using Cache

If the configured interval has not expired, OPcache skips the filesystem check and immediately uses the cached bytecode.

Check the Current Value

Run:

php -i | grep opcache.revalidate_freq

Example:

opcache.revalidate_freq => 2 => 2

Or create a PHP file:

<?php
phpinfo();

Search for:

opcache.revalidate_freq

Locate the Active Configuration File

Run:

php --ini

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.

sudo nano /etc/php.d/10-opcache.ini

Locate:

opcache.revalidate_freq = 2

Example:

opcache.revalidate_freq = 60

Save the file.

Restart PHP-FPM

Apply the changes.

sudo systemctl restart php-fpm

Verify:

sudo systemctl status php-fpm

Expected output:

Active: active (running)

Verify the Configuration

Run:

php -i | grep opcache.revalidate_freq

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.

Directive	Purpose
opcache.validate_timestamps	Enables or disables timestamp validation
opcache.revalidate_freq	Controls how often timestamp validation occurs

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

| Environment                      | Recommended Value |
| -------------------------------- | ----------------- |
| Local development                |                 0 |
| Development server               |               1–2 |
| Testing environment              |              5–10 |
| Production (validation enabled)  |             30–60 |
| Production (validation disabled) |           Ignored |

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

Technology Guides →

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

Southeast Asia Insights →