{"id":2378,"date":"2026-11-03T05:01:04","date_gmt":"2026-11-03T05:01:04","guid":{"rendered":"https:\/\/www.woodcentral.com\/-\/peter\/?p=2378"},"modified":"2026-11-03T05:09:00","modified_gmt":"2026-11-03T05:09:00","slug":"using-opcache","status":"publish","type":"post","link":"https:\/\/www.woodcentral.com\/-\/peter\/using-opcache\/","title":{"rendered":"Using OPcache"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Zend OPcache works automatically once enabled and properly configured. You do not need to add anything to your PHP scripts, HTML pages, or application code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">OPcache operates transparently at the PHP engine level.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How it works<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">When PHP executes a script:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>PHP checks whether its compiled version is already in OPcache.<\/li>\n\n\n\n<li>If it is, PHP executes the cached opcodes.<\/li>\n\n\n\n<li>If it isn&#8217;t, PHP compiles the source and stores the resulting opcodes in shared memory.<\/li>\n\n\n\n<li>Subsequent requests reuse those compiled opcodes.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">This happens automatically.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Configuration worth checking<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In your PHP configuration (<code>php.ini<\/code>), these are the important settings:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>opcache.enable=1\nopcache.enable_cli=0\n\nopcache.memory_consumption=128\nopcache.interned_strings_buffer=16\nopcache.max_accelerated_files=10000\n\nopcache.validate_timestamps=1\nopcache.revalidate_freq=2<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">These are reasonable starting values, not mandatory settings. In particular:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>opcache.enable<\/code>: Enables OPcache for web requests.<\/li>\n\n\n\n<li><code>opcache.memory_consumption<\/code>: Memory allocated for cached opcodes, in MB.<\/li>\n\n\n\n<li><code>opcache.interned_strings_buffer<\/code>: Memory for interned strings.<\/li>\n\n\n\n<li><code>opcache.max_accelerated_files<\/code>: Maximum number of cached script entries.<\/li>\n\n\n\n<li><code>opcache.validate_timestamps<\/code>: Checks whether PHP source files have changed.<\/li>\n\n\n\n<li><code>opcache.revalidate_freq<\/code>: How frequently timestamp checks occur, in seconds.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">With <code>validate_timestamps=1<\/code> and <code>revalidate_freq=2<\/code>, changes to PHP files should generally be recognized within a couple of seconds.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you disable timestamp validation for production performance, remember that you&#8217;ll need to reset OPcache or restart the PHP handler when deploying changed scripts.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How to verify OPcache is working<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Create a temporary PHP file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\necho '&lt;pre&gt;';\nprint_r(opcache_get_status(false));\necho '&lt;\/pre&gt;';<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Look for:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;opcache_enabled] =&gt; 1<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can also inspect:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>opcache_statistics<\/code><\/li>\n\n\n\n<li><code>num_cached_scripts<\/code><\/li>\n\n\n\n<li><code>hits<\/code><\/li>\n\n\n\n<li><code>misses<\/code><\/li>\n\n\n\n<li><code>memory_usage<\/code><\/li>\n\n\n\n<li><code>opcache_hit_rate<\/code><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">These tell you whether scripts are being cached and how effectively OPcache is being used.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Security note: Don&#8217;t leave a publicly accessible diagnostic script on your website. It exposes server configuration information. Delete it after testing.<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-peter-martin wp-block-embed-peter-martin\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"fwsaEjA28E\"><a href=\"https:\/\/www.woodcentral.com\/-\/peter\/memcache-memcached-zend-opcache-and-apcu-understanding-the-differences\/\">Memcache, Memcached, Zend OPcache and APCu: understanding the differences<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; visibility: hidden;\" title=\"\u201cMemcache, Memcached, Zend OPcache and APCu: understanding the differences\u201d \u2014 Peter Martin\" src=\"https:\/\/www.woodcentral.com\/-\/peter\/memcache-memcached-zend-opcache-and-apcu-understanding-the-differences\/embed\/#?secret=lR5h3Uc8kw#?secret=fwsaEjA28E\" data-secret=\"fwsaEjA28E\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Zend OPcache works automatically once enabled and properly configured. You do not need to add anything to your PHP scripts, HTML pages, or application code. OPcache operates transparently at the PHP engine level. How it works When PHP executes a script: This happens automatically. Configuration worth checking In your PHP configuration (php.ini), these are the &#8230; <a title=\"Using OPcache\" class=\"read-more\" href=\"https:\/\/www.woodcentral.com\/-\/peter\/using-opcache\/\" aria-label=\"Read more about Using OPcache\">Read more<\/a><\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-2378","post","type-post","status-publish","format-standard","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/www.woodcentral.com\/-\/peter\/wp-json\/wp\/v2\/posts\/2378","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.woodcentral.com\/-\/peter\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.woodcentral.com\/-\/peter\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.woodcentral.com\/-\/peter\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.woodcentral.com\/-\/peter\/wp-json\/wp\/v2\/comments?post=2378"}],"version-history":[{"count":0,"href":"https:\/\/www.woodcentral.com\/-\/peter\/wp-json\/wp\/v2\/posts\/2378\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.woodcentral.com\/-\/peter\/wp-json\/wp\/v2\/media?parent=2378"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.woodcentral.com\/-\/peter\/wp-json\/wp\/v2\/categories?post=2378"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.woodcentral.com\/-\/peter\/wp-json\/wp\/v2\/tags?post=2378"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}