{"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-26T22:04:27","modified_gmt":"2026-08-26T22:04:27","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: Cut WordPress CPU Usage on Your VPS"},"content":{"rendered":"<p class=\"wp-block-paragraph\">Every PHP request compiles the requested script from source unless the compiled bytecode is already cached in memory. A typical WordPress installation with a dozen plugins contains 500\u20131000 PHP files, and without OPcache, PHP re-parses and re-compiles every single one on each request. That is a tremendous waste of CPU that shows up directly in server load and Time To First Byte (TTFB). OPcache stores compiled bytecode in shared memory, and the realpath cache eliminates repeated filesystem <code>stat()<\/code> calls. This tutorial walks through the exact settings that matter for WordPress on a VPS and how to verify they are working correctly.<\/p>\n\n<h2 class=\"wp-block-heading\">What OPcache Does (and Why Defaults Are Not Enough)<\/h2>\n\n<p class=\"wp-block-paragraph\">OPcache is bundled with PHP and enabled by default in most distributions, but the default settings are tailored for generic PHP applications \u2014 not a plugin-heavy WordPress install. The three settings that control the essentials are:<\/p>\n\n<ul class=\"wp-block-list\"><li><strong>opcache.memory_consumption<\/strong> \u2014 How much shared memory holds compiled scripts (default: 128 MB in PHP 8.x, but often lower in older distro packages)<\/li><li><strong>opcache.max_accelerated_files<\/strong> \u2014 How many distinct files can be cached (default: 4000\u201310000 depending on distribution)<\/li><li><strong>opcache.validate_timestamps<\/strong> \/ <strong>opcache.revalidate_freq<\/strong> \u2014 How often PHP checks if files changed on disk<\/li><\/ul>\n\n<p class=\"wp-block-paragraph\">If you&#8217;re running WordPress on a VPS, you need to tune these settings for your specific workload. <a href=\"https:\/\/virtualserversvps.com\/\">Compare VPS plans with enough CPU headroom<\/a> to get the most out of OPcache optimizations.<\/p>\n\n<h2 class=\"wp-block-heading\">Step 1: Find Your PHP Configuration File<\/h2>\n\n<p class=\"wp-block-paragraph\">OPcache settings go in <code>php.ini<\/code>. For PHP-FPM (the most common setup with Nginx), the file is at:<\/p>\n\n<pre class=\"wp-block-code\"><code># Find your PHP version\nphp -v | head -1\n\n# Edit the FPM php.ini (adjust 8.x to your version)\nsudo nano \/etc\/php\/8.3\/fpm\/php.ini<\/code><\/pre>\n\n<p class=\"wp-block-paragraph\">For Apache with mod_php, edit the Apache php.ini instead (usually <code>\/etc\/php\/8.3\/apache2\/php.ini<\/code>).<\/p>\n\n<h2 class=\"wp-block-heading\">Step 2: Apply the Recommended OPcache Settings<\/h2>\n\n<p class=\"wp-block-paragraph\">Add or update these settings in your <code>php.ini<\/code>:<\/p>\n\n<pre class=\"wp-block-code\"><code>opcache.enable=1\nopcache.memory_consumption=128\nopcache.max_accelerated_files=10000\nopcache.validate_timestamps=1\nopcache.revalidate_freq=60\nopcache.enable_cli=1\nopcache.interned_strings_buffer=16\nopcache.fast_shutdown=1<\/code><\/pre>\n\n<p class=\"wp-block-paragraph\">What each setting does:<\/p>\n\n<ul class=\"wp-block-list\"><li><strong>memory_consumption=128<\/strong> \u2014 A full WordPress install with plugins and a theme typically uses 64\u2013128 MB of bytecode cache. Start at 128 and check usage with <code>opcache_get_status()<\/code>.<\/li><li><strong>max_accelerated_files=10000<\/strong> \u2014 WordPress plus WooCommerce, page builders, and SEO plugins can easily exceed 10,000 files. Set this high enough that <code>num_cached_scripts<\/code> never reaches the limit.<\/li><li><strong>revalidate_freq=60<\/strong> \u2014 Recheck files every 60 seconds so deploys show up quickly without a <code>stat()<\/code> call on every request. If you deploy rarely, set this to 300 or higher.<\/li><li><strong>enable_cli=1<\/strong> \u2014 Cache bytecode for WP-CLI and cron jobs too. This speeds up scheduled tasks significantly.<\/li><li><strong>interned_strings_buffer=16<\/strong> \u2014 Caches repeated strings across PHP files. WordPress uses many duplicate strings (class names, function names, query strings), so this is a cheap win.<\/li><li><strong>fast_shutdown=1<\/strong> \u2014 Enables faster request shutdown sequence. Safe for most setups.<\/li><\/ul>\n\n<h2 class=\"wp-block-heading\">Step 3: Tune the Realpath Cache<\/h2>\n\n<p class=\"wp-block-paragraph\">The realpath cache stores resolved filesystem paths so PHP does not need to call <code>stat()<\/code> every time it <code>include()<\/code>s or <code>require()<\/code>s a file. WordPress does a lot of includes \u2014 every plugin and theme file \u2014 so this cache is important.<\/p>\n\n<p class=\"wp-block-paragraph\">Add these settings to the same <code>php.ini<\/code>:<\/p>\n\n<pre class=\"wp-block-code\"><code>realpath_cache_size=4096k\nrealpath_cache_ttl=600<\/code><\/pre>\n\n<p class=\"wp-block-paragraph\">The default realpath cache size is often 4 MB (4096k), which is sufficient for most WordPress sites. If you have a very large plugin ecosystem (100+ plugins), consider increasing it to 8192k. The TTL of 600 seconds (10 minutes) means resolved paths are cached for 10 minutes before being re-checked \u2014 a good balance between freshness and performance.<\/p>\n\n<h2 class=\"wp-block-heading\">Step 4: Restart PHP-FPM and Verify<\/h2>\n\n<pre class=\"wp-block-code\"><code># Restart PHP-FPM (adjust 8.x to your version)\nsudo systemctl restart php8.3-fpm\n\n# Verify the settings loaded\nphp -i | grep -E \"opcache\\.(enable|memory_consumption|max_accelerated|revalidate|interned_strings)\"<\/code><\/pre>\n\n<p class=\"wp-block-paragraph\">Run a quick cache health check:<\/p>\n\n<pre class=\"wp-block-code\"><code>php -r '\n$status = opcache_get_status(false);\necho \"Memory used: \" . round($status[\"memory_usage\"][\"used_memory\"] \/ 1024 \/ 1024, 2) . \" MB\\n\";\necho \"Memory free: \" . round($status[\"memory_usage\"][\"free_memory\"] \/ 1024 \/ 1024, 2) . \" MB\\n\";\necho \"Cached scripts: \" . $status[\"opcache_statistics\"][\"num_cached_scripts\"] . \"\\n\";\necho \"Hits: \" . $status[\"opcache_statistics\"][\"hits\"] . \"\\n\";\necho \"Misses: \" . $status[\"opcache_statistics\"][\"misses\"] . \"\\n\";\necho \"Hit rate: \" . round($status[\"opcache_statistics\"][\"hit_rate\"], 2) . \"%\\n\";\n'<\/code><\/pre>\n\n<p class=\"wp-block-paragraph\">After a few requests to warm the cache, the hit rate should be above 95%. If it is below 90%, the cache is too small for your codebase \u2014 increase <code>memory_consumption<\/code> or <code>max_accelerated_files<\/code>.<\/p>\n\n<h2 class=\"wp-block-heading\">Step 5: Monitor with a WordPress Admin Dashboard<\/h2>\n\n<p class=\"wp-block-paragraph\">For ongoing monitoring, install a free plugin like OPcache Manager or Query Monitor (which includes OPcache stats). The key figures to watch in the dashboard:<\/p>\n\n<ul class=\"wp-block-list\"><li><strong>Hit rate<\/strong> \u2014 Should stay above 95% after the initial warm-up period<\/li><li><strong>Memory used vs memory size<\/strong> \u2014 If the bar is nearly full, raise <code>opcache.memory_consumption<\/code><\/li><li><strong>Cached scripts vs max cached keys<\/strong> \u2014 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 to a file:<\/p>\n\n<pre class=\"wp-block-code\"><code># Add to crontab -e\n0 6 * * 1 php -r '\n$s = opcache_get_status(false);\nfile_put_contents(\"\/var\/log\/opcache_stats.log\", date(\"Y-m-d H:i:s\") . \" | \" .\n  round($s[\"opcache_statistics\"][\"hit_rate\"], 2) . \"% | \" .\n  $s[\"opcache_statistics\"][\"num_cached_scripts\"] . \" scripts\\n\", FILE_APPEND);\n'<\/code><\/pre>\n\n<h2 class=\"wp-block-heading\">Common Mistakes to Avoid<\/h2>\n\n<ul class=\"wp-block-list\"><li><strong>Memory too low:<\/strong> Setting <code>memory_consumption<\/code> to 32 or 64 MB on a plugin-heavy site \u2014 the cache fills, old scripts are evicted, and hit rate collapses.<\/li><li><strong>validate_timestamps=0 with frequent deploys:<\/strong> Stale bytecode can serve old code after updates. Only disable validation if you clear the cache manually after each deploy.<\/li><li><strong>Forgetting enable_cli=1:<\/strong> WP-CLI and cron jobs run uncached, slowing down scheduled tasks like backups and content updates.<\/li><li><strong>Not restarting PHP-FPM:<\/strong> OPcache settings only load at PHP startup. Changing <code>php.ini<\/code> without restarting has no effect.<\/li><li><strong>Ignoring WooCommerce:<\/strong> WooCommerce and page builders can push file counts past 10,000. Re-check <code>num_cached_scripts<\/code> after adding plugins.<\/li><\/ul>\n\n<h2 class=\"wp-block-heading\">OPcache and PHP 8.x JIT<\/h2>\n\n<p class=\"wp-block-paragraph\">PHP 8.x includes a JIT compiler that can speed up CPU-bound PHP code. For WordPress, however, JIT rarely moves the needle because most of the work is I\/O (database queries, filesystem reads) and not tight CPU loops. JIT also consumes memory that could otherwise hold cached bytecode. Leave JIT off for typical WordPress installs and only enable it if profiling shows genuine CPU-bound PHP work.<\/p>\n\n<h2 class=\"wp-block-heading\">Putting It All 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 larger plan. Pair it with page caching (like Nginx FastCGI Cache or a plugin like WP Rocket) and a CDN for the full performance stack.<\/p>\n\n<p class=\"wp-block-paragraph\">If your current VPS struggles with PHP workloads even after tuning, <a href=\"https:\/\/virtualserversvps.com\/\">browse our VPS provider comparisons<\/a> to find a plan with more CPU headroom and fast NVMe storage.<\/p>","protected":false},"excerpt":{"rendered":"<p>Every PHP request compiles the requested script from source unless the compiled bytecode is already cached in memory. A typical WordPress installation with a dozen plugins contains 500\u20131000 PHP files,&#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":2,"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: Cut WordPress CPU Usage on Your VPS - Virtual Servers VPS Blog<\/title>\n<meta name=\"description\" content=\"Every PHP request compiles the requested script from source unless the compiled bytecode is already cached in memory. A typical WordPress installation\" \/>\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: Cut WordPress CPU Usage on Your VPS\" \/>\n<meta property=\"og:description\" content=\"PHP OPcache and Realpath Cache Tuning: Cut WordPress CPU Usage on Your 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 property=\"article:modified_time\" content=\"2026-08-26T22:04:27+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=\"6 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: Cut WordPress CPU Usage on Your VPS - Virtual Servers VPS Blog\",\"isPartOf\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\"},\"datePublished\":\"2026-08-21T22:49:24+00:00\",\"dateModified\":\"2026-08-26T22:04:27+00:00\",\"author\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\"},\"description\":\"Every PHP request compiles the requested script from source unless the compiled bytecode is already cached in memory. A typical WordPress installation\",\"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: Cut WordPress CPU Usage on Your 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: Cut WordPress CPU Usage on Your VPS - Virtual Servers VPS Blog","description":"Every PHP request compiles the requested script from source unless the compiled bytecode is already cached in memory. A typical WordPress installation","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: Cut WordPress CPU Usage on Your VPS","og_description":"PHP OPcache and Realpath Cache Tuning: Cut WordPress CPU Usage on Your 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","article_modified_time":"2026-08-26T22:04:27+00:00","author":"Virtual-Servers-Vps-Editor","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Virtual-Servers-Vps-Editor","Est. reading time":"6 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: Cut WordPress CPU Usage on Your VPS - Virtual Servers VPS Blog","isPartOf":{"@id":"https:\/\/virtualserversvps.com\/blog\/#website"},"datePublished":"2026-08-21T22:49:24+00:00","dateModified":"2026-08-26T22:04:27+00:00","author":{"@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0"},"description":"Every PHP request compiles the requested script from source unless the compiled bytecode is already cached in memory. A typical WordPress installation","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: Cut WordPress CPU Usage on Your 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":2,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/942\/revisions"}],"predecessor-version":[{"id":977,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/942\/revisions\/977"}],"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}]}}