{
    "title": "OPcache",
    "seo_title": "OPcache: definition, settings and effect on WordPress",
    "h1": "OPcache",
    "description": "OPcache: how PHP keeps compiled code in memory, the useful settings (memory_consumption, revalidate_freq) and the pitfalls to avoid with WordPress.",
    "lead": "OPcache is the PHP extension that keeps already compiled script code (the opcodes) in shared memory. PHP no longer needs to read and parse every file on every request, which greatly speeds up applications like WordPress, made up of hundreds of PHP files loaded on every page.",
    "language": "en",
    "locale": "en-US",
    "type": "definition",
    "url": "https://www.wp-masquerade.com/glossary/opcache/",
    "canonical": "https://www.wp-masquerade.com/glossary/opcache/",
    "markdown": "https://www.wp-masquerade.com/glossary/opcache/index.md",
    "json": "https://www.wp-masquerade.com/glossary/opcache/index.json",
    "published": "2026-10-28T08:00:00+00:00",
    "modified": "2026-10-28T20:08:58+00:00",
    "site": {
        "name": "WP Masquerade",
        "url": "https://www.wp-masquerade.com/"
    },
    "translations": [
        {
            "language": "en",
            "hreflang": "en-US",
            "title": "OPcache",
            "url": "https://www.wp-masquerade.com/glossary/opcache/",
            "markdown": "https://www.wp-masquerade.com/glossary/opcache/index.md",
            "json": "https://www.wp-masquerade.com/glossary/opcache/index.json"
        },
        {
            "language": "fr",
            "hreflang": "fr-FR",
            "title": "OPcache",
            "url": "https://www.wp-masquerade.com/fr/definitions/opcache/",
            "markdown": "https://www.wp-masquerade.com/fr/definitions/opcache/index.md",
            "json": "https://www.wp-masquerade.com/fr/definitions/opcache/index.json"
        },
        {
            "language": "es",
            "hreflang": "es-ES",
            "title": "OPcache",
            "url": "https://www.wp-masquerade.com/es/glosario/opcache/",
            "markdown": "https://www.wp-masquerade.com/es/glosario/opcache/index.md",
            "json": "https://www.wp-masquerade.com/es/glosario/opcache/index.json"
        },
        {
            "language": "de",
            "hreflang": "de-DE",
            "title": "OPcache",
            "url": "https://www.wp-masquerade.com/de/glossar/opcache/",
            "markdown": "https://www.wp-masquerade.com/de/glossar/opcache/index.md",
            "json": "https://www.wp-masquerade.com/de/glossar/opcache/index.json"
        },
        {
            "language": "it",
            "hreflang": "it-IT",
            "title": "OPcache",
            "url": "https://www.wp-masquerade.com/it/glossario/opcache/",
            "markdown": "https://www.wp-masquerade.com/it/glossario/opcache/index.md",
            "json": "https://www.wp-masquerade.com/it/glossario/opcache/index.json"
        },
        {
            "language": "pt",
            "hreflang": "pt-BR",
            "title": "OPcache",
            "url": "https://www.wp-masquerade.com/pt/glossario/opcache/",
            "markdown": "https://www.wp-masquerade.com/pt/glossario/opcache/index.md",
            "json": "https://www.wp-masquerade.com/pt/glossario/opcache/index.json"
        },
        {
            "language": "nl",
            "hreflang": "nl-NL",
            "title": "OPcache",
            "url": "https://www.wp-masquerade.com/nl/woordenlijst/opcache/",
            "markdown": "https://www.wp-masquerade.com/nl/woordenlijst/opcache/index.md",
            "json": "https://www.wp-masquerade.com/nl/woordenlijst/opcache/index.json"
        }
    ],
    "headings": [
        {
            "level": 1,
            "text": "OPcache"
        },
        {
            "level": 2,
            "text": "How OPcache works"
        },
        {
            "level": 2,
            "text": "Useful settings"
        },
        {
            "level": 2,
            "text": "For WordPress"
        },
        {
            "level": 2,
            "text": "Security"
        },
        {
            "level": 2,
            "text": "Common mistakes"
        }
    ],
    "body": "PHP is an interpreted language: before running a file, it reads it, parses it and translates it into internal instructions, the opcodes. Without a cache, this work is redone on every request, for every file loaded. The PHP documentation sums up OPcache's role this way: it stores precompiled script bytecode in shared memory, removing the need for PHP to load and parse scripts on each request.\n\n## How OPcache works\n\nOPcache is an extension bundled with PHP, loaded with the `zend_extension` directive. The first time a file runs, its opcodes are placed in shared memory. Later requests reuse them directly, whichever [PHP-FPM](https://www.wp-masquerade.com/glossary/php-fpm/) worker handles them, since the memory is shared by the processes under the same master.\n\n![Two-column comparison. Without OPcache, on every request: PHP files are read from disk, parsed and compiled into opcodes, executed, then everything is forgotten. With OPcache: opcodes are already in shared memory, execution starts immediately, and file modification times are checked every 2 seconds by default.](https://www.wp-masquerade.com/media/2026/10/opcache-avec-sans-en.webp)\n\n*OPcache removes the compilation step that would otherwise be repeated on every request.*\n\nTo pick up changes, OPcache checks file timestamps every two seconds by default (`opcache.revalidate_freq=2`). If you turn this check off (`opcache.validate_timestamps=0`), a possible gain in production, file changes are no longer seen until the cache is cleared with opcache_reset() or by restarting PHP.\n\n## Useful settings\n\nDefault values documented by PHP:\n\n- `opcache.memory_consumption`: 128 MB of shared memory;\n- `opcache.max_accelerated_files`: 10,000 files at most;\n- `opcache.interned_strings_buffer`: 8 MB for interned strings;\n- `opcache.revalidate_freq`: 2 seconds.\n\nA WordPress site with a page builder, WooCommerce and twenty or so plugins can exceed the planned number of files or memory. Beyond that, some scripts are no longer cached and the gain erodes. The opcache_get_status() function or a diagnostic plugin shows how full the cache is.\n\nSince PHP 7.4, preloading (`opcache.preload`) loads files when PHP starts. It isn't available on Windows and needs a restart to be updated: it suits frozen applications better than a WordPress site that updates often.\n\n*Video: “Everything about OPcache to increase PHP performance (2026)” (Tideways)*\n\n## For WordPress\n\nThe WordPress documentation recommends adding an opcode cache such as OPcache to greatly improve PHP performance. It complements, rather than replaces, the page cache and the [object cache](https://www.wp-masquerade.com/glossary/redis-memcached/): OPcache skips code compilation, the object cache skips database queries, and the page cache skips running PHP.\n\n- On [shared hosting](https://www.wp-masquerade.com/glossary/shared-hosting/), OPcache is normally enabled; check with phpinfo() or in your control panel's PHP settings.\n- On a [VPS](https://www.wp-masquerade.com/glossary/vps/), adjust the memory and number of files to the actual size of your sites.\n- When upgrading to a new PHP version, reload PHP-FPM to start from a clean cache; it's also the time to check that the branch you chose is still supported (see [end-of-life PHP versions](https://www.wp-masquerade.com/end-of-life-php-versions/)).\n\n## Security\n\nOn a shared server, the cache is common to all pools under the same PHP-FPM master. Directives such as `opcache.validate_permission` and `opcache.validate_root` exist to check permissions on cached files and prevent collisions in chroot environments. The `opcache.restrict_api` directive limits use of the OPcache functions to a given path, so that an arbitrary script can't clear the cache. These settings complement those in our guide to hardening PHP.\n\n## Common mistakes\n\nTurning off validate_timestamps and then not understanding why a file change doesn't show up; leaving the default memory on a large site; thinking OPcache replaces a page cache.\n\n## Related terms\n\n- [PHP-FPM](https://www.wp-masquerade.com/glossary/php-fpm/)\n- [Redis and Memcached (object cache)](https://www.wp-masquerade.com/glossary/redis-memcached/)\n- [Shared hosting](https://www.wp-masquerade.com/glossary/shared-hosting/)\n- [VPS (virtual private server)](https://www.wp-masquerade.com/glossary/vps/)\n- [MySQL and MariaDB](https://www.wp-masquerade.com/glossary/mysql-mariadb/)\n\n\n## Sources\n\n- [PHP Manual : OPcache](https://www.php.net/manual/en/book.opcache.php)\n- [PHP Manual : OPcache, runtime configuration](https://www.php.net/manual/en/opcache.configuration.php)\n- [PHP Manual : OPcache, installation](https://www.php.net/manual/en/opcache.installation.php)\n- [WordPress Advanced Administration : Cache](https://developer.wordpress.org/advanced-administration/performance/cache/)",
    "definition": "OPcache is the PHP extension that keeps already compiled script code (the opcodes) in shared memory. PHP no longer needs to read and parse every file on every request, which greatly speeds up applications like WordPress, made up of hundreds of PHP files loaded on every page.",
    "group": "Web hosting",
    "aka": [
        "Zend OPcache",
        "opcode cache",
        "PHP opcode cache",
        "opcache.ini"
    ],
    "related": [
        {
            "title": "PHP-FPM",
            "url": "https://www.wp-masquerade.com/glossary/php-fpm/",
            "markdown": "https://www.wp-masquerade.com/glossary/php-fpm/index.md"
        },
        {
            "title": "Redis and Memcached (object cache)",
            "url": "https://www.wp-masquerade.com/glossary/redis-memcached/",
            "markdown": "https://www.wp-masquerade.com/glossary/redis-memcached/index.md"
        },
        {
            "title": "Shared hosting",
            "url": "https://www.wp-masquerade.com/glossary/shared-hosting/",
            "markdown": "https://www.wp-masquerade.com/glossary/shared-hosting/index.md"
        },
        {
            "title": "VPS (virtual private server)",
            "url": "https://www.wp-masquerade.com/glossary/vps/",
            "markdown": "https://www.wp-masquerade.com/glossary/vps/index.md"
        },
        {
            "title": "MySQL and MariaDB",
            "url": "https://www.wp-masquerade.com/glossary/mysql-mariadb/",
            "markdown": "https://www.wp-masquerade.com/glossary/mysql-mariadb/index.md"
        }
    ],
    "sources": [
        {
            "title": "PHP Manual : OPcache",
            "url": "https://www.php.net/manual/en/book.opcache.php"
        },
        {
            "title": "PHP Manual : OPcache, runtime configuration",
            "url": "https://www.php.net/manual/en/opcache.configuration.php"
        },
        {
            "title": "PHP Manual : OPcache, installation",
            "url": "https://www.php.net/manual/en/opcache.installation.php"
        },
        {
            "title": "WordPress Advanced Administration : Cache",
            "url": "https://developer.wordpress.org/advanced-administration/performance/cache/"
        }
    ],
    "format": "application/json"
}