{"id":1834,"date":"2026-11-25T03:58:47","date_gmt":"2026-11-25T03:58:47","guid":{"rendered":"https:\/\/virtualserversvps.com\/blog\/?p=1834"},"modified":"2026-11-25T03:58:47","modified_gmt":"2026-11-25T03:58:47","slug":"php-opcache-preload-validate-timestamps","status":"publish","type":"post","link":"https:\/\/virtualserversvps.com\/blog\/php-opcache-preload-validate-timestamps\/","title":{"rendered":"PHP OPcache Preload and validate_timestamps on a VPS: What Actually Saves CPU"},"content":{"rendered":"<div style=\"padding:20px\">\n<h2>Why validate_timestamps Quietly Burns CPU<\/h2>\n<p>Every PHP request with OPcache enabled runs a stat check on every included file when <code>opcache.validate_timestamps=1<\/code>, the default. On a WordPress site with 200 to 400 included files, that is hundreds of <code>stat()<\/code> calls per request. On local SSD it is cheap; on a VPS with a busy overlay filesystem or a network-backed volume it is not, and it scales linearly with traffic.<\/p>\n<p>Measure first with <code>php -i | grep -E \"validate_timestamps|revalidate_freq\"<\/code>. On a typical 2 vCPU box serving 40 requests per second with 300 files each, that is 12,000 stats per second that produce identical answers between deploys. The fix is not &#8220;turn it off blindly&#8221; \u2014 it is to understand what you are trading when you do.<\/p>\n<h2>What Preloading Actually Buys You<\/h2>\n<p><code>opcache.preload<\/code> points at a file that is executed once at FPM worker startup, and every class and function it loads is compiled and held in shared memory for the life of the pool. With <code>opcache.preload_user=www-data<\/code> and a preload script that requires your framework bootstrap and hot classes, a cold worker start stops paying the compile cost for the core of the application.<\/p>\n<p>The gain is real but bounded: preloading removes compile time from worker startup and improves the first-request latency after a reload. It does not speed up steady-state execution, because OPcache already serves compiled bytecode from shared memory. That is why a <a href=\"https:\/\/virtualserversvps.com\/\">virtualserversvps.com<\/a> box with a fixed vCPU count makes the measurement trustworthy \u2014 run with <code>ab -n 200 -c 5<\/code> against a cold <code>systemctl reload php8.3-fpm<\/code> before and after, and expect single-digit millisecond improvements per request, not 10x.<\/p>\n<h2>Write a Preload Script That Does Not Recurse<\/h2>\n<p>A workable pattern is a small file that sets a fixed class list and loops over it. Put the list in <code>\/etc\/php\/8.3\/fpm\/preload.php<\/code> and reference it with <code>opcache.preload=\/etc\/php\/8.3\/fpm\/preload.php<\/code>. Use <code>class_exists($class, true)<\/code> inside the loop and skip anything that fails to load, because one missing class aborts the whole preload at startup and the pool fails to come up.<\/p>\n<p>The common failure is preloading a class that depends on request-scoped state or on an extension loaded later. Keep the list to framework core, service container classes and frequently used value objects. If you see <code>PHP Fatal error: Cannot declare class<\/code> in the FPM log, you have a duplicate include or an autoloader conflict, not a memory limit problem.<\/p>\n<h2>Decide Whether Timestamps Can Be Disabled<\/h2>\n<p>Setting <code>opcache.validate_timestamps=0<\/code> removes all per-request stat calls. It is safe only when deploys are explicit and followed by an FPM reload, which is how a controlled release pipeline works. If the site edits theme files through wp-admin or an FTP client, disabling it will leave users on stale code for hours, and that is a worse failure than the CPU cost.<\/p>\n<p>The middle path is <code>validate_timestamps=1<\/code> with <code>revalidate_freq=60<\/code>. That caps the check at once per minute per file rather than once per request, which cuts the stat volume by the request-rate factor while keeping edits visible within a minute. For a 2 vCPU VPS this is usually the right setting: predictable correctness with a small fraction of the overhead.<\/p>\n<h2>Size the Shared Memory Segment Honestly<\/h2>\n<p>Check <code>opcache_get_status()['memory_usage']<\/code> under load, or run <code>php -r 'print_r(opcache_get_status(false)[\"memory_usage\"]);'<\/code> from CLI with the same ini. If <code>used_memory<\/code> sits above 70 percent of <code>opcache.memory_consumption<\/code>, you are evicting scripts and recompiling them on the next request, which silently negates every other tuning change on this page.<\/p>\n<p>Raise it in steps of 32M up to <code>256<\/code> or <code>384<\/code>, watching <code>opcache_statistics.num_cached_scripts<\/code> and the <code>oom_restarts<\/code> counter. A non-zero <code>oom_restarts<\/code> with a climbing <code>hash_restarts<\/code> is the signature of an undersized segment. Each cached script costs a few kilobytes of shared memory plus the compiled bytecode, so 128M is often enough for a mid-size WordPress and far too little for a large Laravel application.<\/p>\n<h2>Check Hash Table and JIT Settings Together<\/h2>\n<p><code>opcache.max_accelerated_files<\/code> must exceed the number of PHP files in the application. The default 7,963 is fine for small projects; a large framework with vendors can exceed 20,000. Set it to 16,257 or 32,509 \u2014 these are primes the engine rounds to \u2014 and monitor <code>hash_restarts<\/code> in the statistics; any increase at steady state means the table is too small.<\/p>\n<p>JIT is a separate decision. <code>opcache.jit=tracing<\/code> with <code>opcache.jit_buffer_size=64M<\/code> helps CPU-bound code and often hurts database-bound WordPress, where it also reserves memory that the buffer pool wants. Test with <code>ab<\/code> rather than assuming \u2014 and remember that a 64M JIT buffer on a 1 GB VPS is a real subtraction from your PHP-FPM headroom.<\/p>\n<h2>Put It Together and Verify With Numbers<\/h2>\n<p>A defensible low-memory configuration is <code>opcache.memory_consumption=192<\/code>, <code>opcache.max_accelerated_files=16257<\/code>, <code>opcache.validate_timestamps=1<\/code>, <code>opcache.revalidate_freq=60<\/code>, <code>opcache.preload<\/code> pointing at a curated class list, and JIT disabled unless you have measured a win. That costs about 200 MB of shared memory on a 2 GB VPS and removes the compile path from every request.<\/p>\n<p>Confirm with <code>php -i | grep -i opcache<\/code>, a cold <code>wrk -c25 -d30s --latency<\/code> against a dynamic page, and the post-reload first-request time. If the numbers move by less than 5 percent, keep the change anyway for the stat reduction \u2014 but do not claim a speed improvement you cannot show. When memory is the actual constraint, more RAM on a <a href=\"https:\/\/virtualserversvps.com\/\">virtualserversvps.com<\/a> plan solves it faster than shaving the OPcache segment, since a small segment means recompiles, not savings.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Every PHP request with OPcache enabled runs a stat check on every included file when opcache.validate_timestamps=1, the default. On a WordPress site with 200 to 400 included files, that is hundreds of stat() calls&#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":[1],"tags":[],"class_list":["post-1834","post","type-post","status-publish","format-standard","hentry","category-vps-guides-tutorials"],"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 Preload and validate_timestamps on a VPS: What Actually Saves CPU - Virtual Servers VPS Blog<\/title>\n<meta name=\"description\" content=\"Every PHP request with OPcache enabled runs a stat check on every included file when opcache.validate_timestamps=1, the default. On a WordPress site with 200 to 400 included files, that is hundreds of stat() calls...\" \/>\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-preload-validate-timestamps\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PHP OPcache Preload and validate_timestamps on a VPS: What Actually Saves CPU\" \/>\n<meta property=\"og:description\" content=\"PHP OPcache Preload and validate_timestamps on a VPS: What Actually Saves CPU\" \/>\n<meta property=\"og:url\" content=\"https:\/\/virtualserversvps.com\/blog\/php-opcache-preload-validate-timestamps\/\" \/>\n<meta property=\"og:site_name\" content=\"Virtual Servers VPS Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-11-25T03:58:47+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-preload-validate-timestamps\/\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/php-opcache-preload-validate-timestamps\/\",\"name\":\"PHP OPcache Preload and validate_timestamps on a VPS: What Actually Saves CPU - Virtual Servers VPS Blog\",\"isPartOf\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\"},\"datePublished\":\"2026-11-25T03:58:47+00:00\",\"author\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\"},\"description\":\"Every PHP request with OPcache enabled runs a stat check on every included file when opcache.validate_timestamps=1, the default. On a WordPress site with 200 to 400 included files, that is hundreds of stat() calls...\",\"breadcrumb\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/php-opcache-preload-validate-timestamps\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/virtualserversvps.com\/blog\/php-opcache-preload-validate-timestamps\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/php-opcache-preload-validate-timestamps\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/virtualserversvps.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PHP OPcache Preload and validate_timestamps on a VPS: What Actually Saves CPU\"}]},{\"@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 Preload and validate_timestamps on a VPS: What Actually Saves CPU - Virtual Servers VPS Blog","description":"Every PHP request with OPcache enabled runs a stat check on every included file when opcache.validate_timestamps=1, the default. On a WordPress site with 200 to 400 included files, that is hundreds of stat() calls...","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-preload-validate-timestamps\/","og_locale":"en_US","og_type":"article","og_title":"PHP OPcache Preload and validate_timestamps on a VPS: What Actually Saves CPU","og_description":"PHP OPcache Preload and validate_timestamps on a VPS: What Actually Saves CPU","og_url":"https:\/\/virtualserversvps.com\/blog\/php-opcache-preload-validate-timestamps\/","og_site_name":"Virtual Servers VPS Blog","article_published_time":"2026-11-25T03:58:47+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-preload-validate-timestamps\/","url":"https:\/\/virtualserversvps.com\/blog\/php-opcache-preload-validate-timestamps\/","name":"PHP OPcache Preload and validate_timestamps on a VPS: What Actually Saves CPU - Virtual Servers VPS Blog","isPartOf":{"@id":"https:\/\/virtualserversvps.com\/blog\/#website"},"datePublished":"2026-11-25T03:58:47+00:00","author":{"@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0"},"description":"Every PHP request with OPcache enabled runs a stat check on every included file when opcache.validate_timestamps=1, the default. On a WordPress site with 200 to 400 included files, that is hundreds of stat() calls...","breadcrumb":{"@id":"https:\/\/virtualserversvps.com\/blog\/php-opcache-preload-validate-timestamps\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/virtualserversvps.com\/blog\/php-opcache-preload-validate-timestamps\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/virtualserversvps.com\/blog\/php-opcache-preload-validate-timestamps\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/virtualserversvps.com\/blog\/"},{"@type":"ListItem","position":2,"name":"PHP OPcache Preload and validate_timestamps on a VPS: What Actually Saves CPU"}]},{"@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\/1834","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=1834"}],"version-history":[{"count":1,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/1834\/revisions"}],"predecessor-version":[{"id":1837,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/1834\/revisions\/1837"}],"wp:attachment":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/media?parent=1834"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/categories?post=1834"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/tags?post=1834"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}