{"id":942,"date":"2026-08-21T22:49:24","date_gmt":"2026-08-21T22:49:24","guid":{"rendered":"https:\/\/virtualserversvps.com\/blog\/?p=942"},"modified":"2026-08-21T22:49:24","modified_gmt":"2026-08-21T22:49:24","slug":"php-opcache-realpath-cache-wordpress-vps-tuning","status":"publish","type":"post","link":"https:\/\/virtualserversvps.com\/blog\/php-opcache-realpath-cache-wordpress-vps-tuning\/","title":{"rendered":"PHP OPcache and Realpath Cache Tuning for WordPress on a VPS"},"content":{"rendered":"<p class=\"wp-block-paragraph\">Every PHP request compiles the requested script from source unless the compiled bytecode is already cached. A typical WordPress installation contains several hundred PHP files, and without OPcache, PHP re-parses and re-compiles them on every single request \u2014 a waste of CPU that shows up directly in TTFB and throughput. OPcache stores compiled bytecode in shared memory, and its smaller cousin, the realpath cache, avoids repeated filesystem <code>stat()<\/code> calls. This guide covers the settings that matter for WordPress on a VPS and how to verify they are working.<\/p>\n\n<h2 class=\"wp-block-heading\">What OPcache does<\/h2>\n\n<p class=\"wp-block-paragraph\">OPcache is bundled with PHP and enabled by default in most distributions, but the defaults are conservative. Three settings control the essentials:<\/p>\n\n<ul class=\"wp-block-list\"><li><code>opcache.memory_consumption<\/code> \u2014 how much shared memory holds compiled scripts<\/li><li><code>opcache.max_accelerated_files<\/code> \u2014 how many distinct files can be cached<\/li><li><code>opcache.validate_timestamps<\/code> \/ <code>opcache.revalidate_freq<\/code> \u2014 how often PHP checks files for changes<\/li><\/ul>\n\n<h2 class=\"wp-block-heading\">Recommended OPcache settings for WordPress<\/h2>\n\n<p class=\"wp-block-paragraph\">Put these in <code>php.ini<\/code> (for PHP-FPM, that is usually <code>\/etc\/php\/8.x\/fpm\/php.ini<\/code>):<\/p>\n\n<p class=\"wp-block-paragraph\"><code>opcache.enable=1<br>opcache.memory_consumption=128<br>opcache.max_accelerated_files=10000<br>opcache.validate_timestamps=1<br>opcache.revalidate_freq=60<br>opcache.enable_cli=1<br>opcache.interned_strings_buffer=16<\/code><\/p>\n\n<ul class=\"wp-block-list\"><li><code>memory_consumption=128<\/code> \u2014 a full WordPress install with plugins and a theme typically uses 64\u2013128 MB of bytecode cache; start at 128 and check usage<\/li><li><code>max_accelerated_files=10000<\/code> \u2014 WordPress plus a plugin-heavy setup easily exceeds the default of 4000\u201310000; set it high enough that <code>opcache_get_status()<\/code> shows no &#8220;full&#8221; warnings<\/li><li><code>revalidate_freq=60<\/code> \u2014 recheck files every 60 seconds so deploys show up quickly without a stat() call on every request<\/li><li><code>enable_cli=1<\/code> \u2014 cache bytecode for WP-CLI and cron jobs too<\/li><\/ul>\n\n<h2 class=\"wp-block-heading\">Tuning the realpath cache<\/h2>\n\n<p class=\"wp-block-paragraph\">Every <code>include<\/code> or <code>require<\/code> triggers a filesystem lookup unless the resolved path is cached. The realpath cache stores those resolutions:<\/p>\n\n<p class=\"wp-block-paragraph\"><code>realpath_cache_size=4096k<br>realpath_cache_ttl=600<\/code><\/p>\n\n<p class=\"wp-block-paragraph\">On a busy WordPress site with many plugins, the default 4 MB realpath cache can fill quickly. Raising it to 4096 KB (or more on larger setups) reduces <code>stat()<\/code> syscalls noticeably \u2014 a cheap win that costs almost no memory.<\/p>\n\n<h2 class=\"wp-block-heading\">Where the settings go<\/h2>\n\n<p class=\"wp-block-paragraph\">For PHP-FPM, edit <code>\/etc\/php\/8.x\/fpm\/php.ini<\/code>, then restart: <code>systemctl restart php8.x-fpm<\/code>. For Apache mod_php, edit the CLI and Apache php.ini files instead. Verify the settings loaded with <code>php -i | grep opcache<\/code> or check <code>opcache_get_status()<\/code> from a small PHP script.<\/p>\n\n<h2 class=\"wp-block-heading\">Verifying the cache is working<\/h2>\n\n<p class=\"wp-block-paragraph\">Create a tiny script with <code>phpinfo()<\/code> or run this one-liner to inspect cache health:<\/p>\n\n<p class=\"wp-block-paragraph\"><code>php -r \"var_export(opcache_get_status());\"<\/code><\/p>\n\n<p class=\"wp-block-paragraph\">Look at these fields:<\/p>\n\n<ul class=\"wp-block-list\"><li><code>hits<\/code> vs <code>misses<\/code> \u2014 hits should be in the high thousands of percent of misses after warm-up; if misses keep growing, the cache is too small<\/li><li><code>memory_used<\/code> vs <code>memory_size<\/code> \u2014 if used approaches the limit, raise <code>memory_consumption<\/code><\/li><li><code>num_cached_scripts<\/code> vs <code>max_cached_keys<\/code> \u2014 if equal, raise <code>max_accelerated_files<\/code><\/li><\/ul>\n\n<p class=\"wp-block-paragraph\">A healthy cache shows near-100% hit rates after the first few requests, which means PHP is serving precompiled bytecode instead of re-parsing source.<\/p>\n\n<h2 class=\"wp-block-heading\">Checking OPcache from the WordPress admin<\/h2>\n\n<p class=\"wp-block-paragraph\">If you prefer a visual check, install a small plugin such as OPcache Manager or use a standalone status script placed outside the web root. Both read <code>opcache_get_status()<\/code> and render the same numbers \u2014 hits, misses, memory used, and cached scripts \u2014 in a readable dashboard. The key figures to watch:<\/p>\n\n<ul class=\"wp-block-list\"><li>Hit rate: should settle above 95% after warm-up; below that, raise memory or file limits<\/li><li>Memory used vs memory size: if the bar is nearly full, raise <code>opcache.memory_consumption<\/code><\/li><li>Cached scripts vs max cached keys: if they are equal, raise <code>max_accelerated_files<\/code><\/li><\/ul>\n\n<p class=\"wp-block-paragraph\">Set up a weekly cron job that logs these numbers, so a plugin update that blows past the cache limits shows up in your monitoring before it slows the site down.<\/p>\n\n<h2 class=\"wp-block-heading\">OPcache and PHP 8.x JIT<\/h2>\n\n<p class=\"wp-block-paragraph\">PHP 8.0 and later include a JIT compiler that can further speed up CPU-heavy PHP code. For WordPress, JIT rarely moves the needle because most of the work is I\/O and database queries, not tight loops \u2014 and JIT consumes memory that could otherwise hold cached bytecode. A reasonable compromise is to leave JIT off for typical WordPress installs and enable it only if profiling shows genuine CPU-bound PHP work.<\/p>\n\n<h2 class=\"wp-block-heading\">Common mistakes<\/h2>\n\n<ul class=\"wp-block-list\"><li>Setting <code>memory_consumption<\/code> too low: the cache fills, old scripts get evicted, and hit rate collapses<\/li><li>Leaving <code>validate_timestamps=0<\/code> in production with frequent deploys: stale bytecode can serve old code after updates<\/li><li>Forgetting <code>enable_cli=1<\/code>: cron jobs and WP-CLI run uncached and slow down scheduled tasks<\/li><li>Ignoring WooCommerce and plugin-heavy builds: they easily push file counts past 10,000, so re-check <code>num_cached_scripts<\/code> after adding plugins<\/li><li>Not restarting PHP-FPM after changing <code>php.ini<\/code>: OPcache settings only load at startup<\/li><\/ul>\n\n<h2 class=\"wp-block-heading\">Putting it together<\/h2>\n\n<p class=\"wp-block-paragraph\">OPcache tuning is one of the highest-return changes you can make on a WordPress VPS: it reduces CPU usage, lowers TTFB, and often delays the need for a bigger plan. Pair it with page caching and a CDN for the full effect.<\/p>\n\n<p class=\"wp-block-paragraph\">If your current VPS struggles with PHP workloads, see the full VPS comparison on our table to find a plan with more CPU headroom, and browse our provider breakdowns and buying guides on the main site for more WordPress and PHP performance guides.<\/p>\n\n<p class=\"wp-block-paragraph\">Looking for a place to run these setups? <a href=\"https:\/\/interserver.net\/vps?id=1067805&amp;sid=virtualserversvps\" rel=\"noreferrer noopener sponsored\" target=\"_blank\">InterServer VPS plans<\/a> offer straightforward pricing with plenty of headroom, and <a href=\"https:\/\/cloudways.com\/en\/?id=2010927&amp;data1=virtualserversvps\" rel=\"noreferrer noopener sponsored\" target=\"_blank\">Cloudways managed cloud hosting<\/a> is a solid choice if you prefer a managed platform on top of fast infrastructure. (Disclosure: we may earn a commission if you sign up through these links, at no extra cost to you.)<\/p>","protected":false},"excerpt":{"rendered":"<p>Every PHP request compiles the requested script from source unless the compiled bytecode is already cached. A typical WordPress installation contains several hundred PHP files, and without OPcache, PHP re-parses&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":0,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-942","post","type-post","status-publish","format-standard","hentry","category-performance-optimization"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.1 (Yoast SEO v26.1) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>PHP OPcache and Realpath Cache Tuning for WordPress on a VPS - Virtual Servers VPS Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/virtualserversvps.com\/blog\/php-opcache-realpath-cache-wordpress-vps-tuning\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PHP OPcache and Realpath Cache Tuning for WordPress on a VPS\" \/>\n<meta property=\"og:description\" content=\"PHP OPcache and Realpath Cache Tuning for WordPress on a VPS\" \/>\n<meta property=\"og:url\" content=\"https:\/\/virtualserversvps.com\/blog\/php-opcache-realpath-cache-wordpress-vps-tuning\/\" \/>\n<meta property=\"og:site_name\" content=\"Virtual Servers VPS Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-08-21T22:49:24+00:00\" \/>\n<meta name=\"author\" content=\"Virtual-Servers-Vps-Editor\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Virtual-Servers-Vps-Editor\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/php-opcache-realpath-cache-wordpress-vps-tuning\/\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/php-opcache-realpath-cache-wordpress-vps-tuning\/\",\"name\":\"PHP OPcache and Realpath Cache Tuning for WordPress on a VPS - Virtual Servers VPS Blog\",\"isPartOf\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\"},\"datePublished\":\"2026-08-21T22:49:24+00:00\",\"author\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\"},\"breadcrumb\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/php-opcache-realpath-cache-wordpress-vps-tuning\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/virtualserversvps.com\/blog\/php-opcache-realpath-cache-wordpress-vps-tuning\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/php-opcache-realpath-cache-wordpress-vps-tuning\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/virtualserversvps.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PHP OPcache and Realpath Cache Tuning for WordPress on a VPS\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/\",\"name\":\"Virtual Servers VPS Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/virtualserversvps.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\",\"name\":\"Virtual-Servers-Vps-Editor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g\",\"caption\":\"Virtual-Servers-Vps-Editor\"},\"sameAs\":[\"https:\/\/virtualserversvps.com\/blog\"],\"url\":\"https:\/\/virtualserversvps.com\/blog\/author\/virtualserversvps\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"PHP OPcache and Realpath Cache Tuning for WordPress on a VPS - Virtual Servers VPS Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/virtualserversvps.com\/blog\/php-opcache-realpath-cache-wordpress-vps-tuning\/","og_locale":"en_US","og_type":"article","og_title":"PHP OPcache and Realpath Cache Tuning for WordPress on a VPS","og_description":"PHP OPcache and Realpath Cache Tuning for WordPress on a VPS","og_url":"https:\/\/virtualserversvps.com\/blog\/php-opcache-realpath-cache-wordpress-vps-tuning\/","og_site_name":"Virtual Servers VPS Blog","article_published_time":"2026-08-21T22:49:24+00:00","author":"Virtual-Servers-Vps-Editor","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Virtual-Servers-Vps-Editor","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/virtualserversvps.com\/blog\/php-opcache-realpath-cache-wordpress-vps-tuning\/","url":"https:\/\/virtualserversvps.com\/blog\/php-opcache-realpath-cache-wordpress-vps-tuning\/","name":"PHP OPcache and Realpath Cache Tuning for WordPress on a VPS - Virtual Servers VPS Blog","isPartOf":{"@id":"https:\/\/virtualserversvps.com\/blog\/#website"},"datePublished":"2026-08-21T22:49:24+00:00","author":{"@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0"},"breadcrumb":{"@id":"https:\/\/virtualserversvps.com\/blog\/php-opcache-realpath-cache-wordpress-vps-tuning\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/virtualserversvps.com\/blog\/php-opcache-realpath-cache-wordpress-vps-tuning\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/virtualserversvps.com\/blog\/php-opcache-realpath-cache-wordpress-vps-tuning\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/virtualserversvps.com\/blog\/"},{"@type":"ListItem","position":2,"name":"PHP OPcache and Realpath Cache Tuning for WordPress on a VPS"}]},{"@type":"WebSite","@id":"https:\/\/virtualserversvps.com\/blog\/#website","url":"https:\/\/virtualserversvps.com\/blog\/","name":"Virtual Servers VPS Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/virtualserversvps.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0","name":"Virtual-Servers-Vps-Editor","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g","caption":"Virtual-Servers-Vps-Editor"},"sameAs":["https:\/\/virtualserversvps.com\/blog"],"url":"https:\/\/virtualserversvps.com\/blog\/author\/virtualserversvps\/"}]}},"_links":{"self":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/942","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/comments?post=942"}],"version-history":[{"count":1,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/942\/revisions"}],"predecessor-version":[{"id":944,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/942\/revisions\/944"}],"wp:attachment":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/media?parent=942"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/categories?post=942"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/tags?post=942"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}