{"id":5443351,"date":"2023-04-11T12:34:40","date_gmt":"2023-04-11T10:34:40","guid":{"rendered":"https:\/\/wp-rocket.me\/?post_type=caching_hub&#038;p=5443351"},"modified":"2023-05-10T15:34:47","modified_gmt":"2023-05-10T13:34:47","slug":"what-is-opcache","status":"publish","type":"caching_hub","link":"https:\/\/wp-rocket.me\/wordpress-cache\/what-is-opcache\/","title":{"rendered":"What is OPcache and How Do You Use It?"},"content":{"rendered":"<p>You can speed up your WordPress site so it\u2019s around three times faster or more with the OPcache PHP OPcode caching system.<\/p><p>OPcache is a type of caching system that saves precompiled script bytecode in a server\u2019s memory called a cache, so each time a user visits a web page, it loads faster.<\/p><p>Here\u2019s more detail on OPcache and how to install it for your WordPress site to speed it up.<\/p><h2 class=\"wp-block-heading\">What is Caching?<\/h2><p>Caching is a system you can put in place to speed up your site. It works by saving content to your server\u2019s memory the first time it\u2019s loaded on a web page. Each subsequent page load has the stored content retrieved from memory and served on the page.<\/p><p>This process means cached content is displayed a lot faster than if it\u2019s loaded directly from the server.<\/p><p>It\u2019s like memorizing your multiplication tables. Once you have memorized it, it\u2019s so much faster to recite the answer to a multiplication problem from memory rather than trying to calculate the answer all over again.<\/p><p>A cache works in a similar way. Content is stored in a server\u2019s memory so it can be loaded from there quickly instead of going all the way to the server to load the content which takes more time. <\/p><p>The result is a faster-loading WordPress website.<\/p><p>There are also <a href=\"https:\/\/wp-rocket.me\/blog\/different-types-of-caching\/\">different types of caching such as browser, site, object, and OPcode caching<\/a>. It\u2019s recommended that you implement more than one kind to increase your site\u2019s performance.<\/p><p>For details, you can also check out these resources:<\/p><ul class=\"wp-block-list\"><li><a href=\"https:\/\/wp-rocket.me\/blog\/wordpress-page-caching-explained-in-plain-english\/\">Caching for WordPress, Explained in Plain English<\/a><\/li>\n\n<li><a href=\"https:\/\/wp-rocket.me\/blog\/browser-cache-vs-cookies-difference\/\">Browser Cache vs Cookies: What\u2019s the Difference?<\/a><\/li>\n\n<li><a href=\"https:\/\/wp-rocket.me\/blog\/object-caching-use-wordpress\/\">What is Object Caching and How to Use It With WordPress<\/a><\/li><\/ul><h2 class=\"wp-block-heading\">What is OPcache or PHP Opcode Caching?<\/h2><p><a href=\"https:\/\/wp-rocket.me\/blog\/what-is-opcache\/\">OPcache is a type of <strong>OPcode caching<\/strong><\/a><strong>.<\/strong> This kind of caching compiles human-readable PHP code to code your server understands which is called opcode. This occurs when the PHP file loads on a web page for the first time. Then, it\u2019s saved to the server\u2019s memory for faster loading at each subsequent page visit.<\/p><p>Bytecode cache engines such as <a href=\"https:\/\/www.php.net\/manual\/en\/book.opcache.php\">OPcache<\/a>, <a href=\"https:\/\/secure.php.net\/manual\/en\/book.apc.php\">APC<\/a>, and <a href=\"https:\/\/xcache.lighttpd.net\/\">Xcache<\/a> all complete this process the first time the PHP file is executed without having to do it a second, or third time.<\/p><h3 class=\"wp-block-heading\">How PHP Opcode Caching Works<\/h3><p>When a PHP script executes, your server\u2019s cache memory is checked to see if the script has already been cached. If it hasn\u2019t, it\u2019s parsed, which means the code is analyzed.<\/p><p>Then, the script is compiled into opcode making the file readable by the server. Once that\u2019s done, the opcode is saved to the server\u2019s memory.<\/p><p>In other words, it\u2019s stored in your server\u2019s cache. The next time a visitor loads the page with the PHP script, the cached code is executed and loaded much faster.<\/p><p>On the other hand, if the script is loaded on the page and the cache is checked for opcode and finds it, then it\u2019s loaded lickety-split.<\/p><figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"800\" src=\"https:\/\/wp-rocket.me\/wp-content\/uploads\/2023\/04\/wp-rocket-opcache-execute-code.png\" alt=\"When PHP scripts aren\u2019t in the cache, they\u2019re cached for subsequent page loads.\" class=\"wp-image-5443505\" srcset=\"https:\/\/wp-rocket.me\/wp-content\/uploads\/2023\/04\/wp-rocket-opcache-execute-code.png 800w, https:\/\/wp-rocket.me\/wp-content\/uploads\/2023\/04\/wp-rocket-opcache-execute-code-195x195.png 195w, https:\/\/wp-rocket.me\/wp-content\/uploads\/2023\/04\/wp-rocket-opcache-execute-code-768x768.png 768w, https:\/\/wp-rocket.me\/wp-content\/uploads\/2023\/04\/wp-rocket-opcache-execute-code-60x60.png 60w, https:\/\/wp-rocket.me\/wp-content\/uploads\/2023\/04\/wp-rocket-opcache-execute-code-90x90.png 90w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><figcaption class=\"wp-element-caption\"><em>When PHP scripts aren\u2019t in the cache, they\u2019re cached for subsequent page loads.<\/em><\/figcaption><\/figure><h3 class=\"wp-block-heading\">The Differences Between OPcache and APC Caches<\/h3><p>OPcache, APC as well as Xcache are all opcode caching systems. OPcache used to be owned by Zend and Alternative PHP Cache (APC) was a free, open-source extension for PHP. Xcache was also an alternative option.<\/p><p>APC was widely used, but it didn\u2019t have the backing that OPcache had so it could be well maintained and stable with each new PHP release.<\/p><p>Fortunately, Zend made OPcache open source and available as an extension since PHP version 5.5. In earlier versions, you have the choice to use APC or OPcache, but if you would like to use the latter, you need to manually install it.<\/p><p>Xcache, on the other hand, is a good alternative to OPcache as a PHP accelerator.<\/p><h3 class=\"wp-block-heading\">Will OPcache Speed up My WordPress Site?<\/h3><p>All three options are suitable for WordPress, but <a href=\"https:\/\/docs.wp-rocket.me\/article\/673-what-is-opcache\">the recommended option for PHP version 5.5 and above is OPcache<\/a>. On average, it speeds up WordPress threefold, at the very least for medium to large sites.<\/p><p>If you have a smaller site without many additional PHP scripts or plugins installed, you likely won\u2019t notice much of a difference.<\/p><p>However, you can still install OPcache on even small WordPress sites with no negative effects other than a slight increase in memory usage. But, it won\u2019t be enough to cause any issues. This is similar for medium, large, or enterprise sites.<\/p><div id=\"om-olkrjzfbhlynbs54rv6z-holder\"><\/div>\n\t<script>(function (d, u, ac) {\n\t\t\tvar s = d.createElement('script')\n\t\t\ts.type = 'text\/javascript'\n\t\t\ts.src = 'https:\/\/a.omappapi.com\/app\/js\/api.min.js'\n\t\t\ts.async = true\n\t\t\ts.dataset.user = u\n\t\t\ts.dataset.campaign = ac\n\t\t\td.getElementsByTagName('head')[0].appendChild(s)\n\t\t})(document, 20440, 'olkrjzfbhlynbs54rv6z')<\/script><h2 class=\"wp-block-heading\">How to Install OPcache on Your Server<\/h2><p>If you have<strong> PHP version 5.5 and above<\/strong>, OPcache PHP opcode caching is installed and enabled by default. You don\u2019t have to do anything else. There are also no additional requirements or configurations needed to run it.<\/p><p>That\u2019s also why you won\u2019t find any options if you were to look for them.<\/p><p>For details, check out <a href=\"https:\/\/wp-rocket.me\/blog\/why-you-need-to-upgrade-to-php-7-asap-and-how-to-do-it-right-now\/\">Why You Need to Upgrade to PHP 7+ ASAP. (and How to Do It Right Now)<\/a><\/p><p><a href=\"https:\/\/www.php.net\/manual\/en\/opcache.installation.php\">According to the PHP manual<\/a>:<\/p><blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\u201cOPcache can only be compiled as a shared extension. If you have disabled the building of default extensions with <strong>&#8211;disable-all<\/strong>, you must compile PHP with the <strong>&#8211;enable-opcache<\/strong> option for OPcache to be available.<br>Once compiled, you can use the <a href=\"https:\/\/www.php.net\/manual\/en\/ini.core.php#ini.zend-extension\">zend_extension<\/a> configuration directive to load the OPcache PHP opcode caching&nbsp; extension into PHP. This can be done with <em>zend_extension=\/full\/path\/to\/opcache.so<\/em> on non-Windows platforms, and <em>zend_extension=C:\\path\\to\\php_opcache.dll<\/em> on Windows.\u201d<\/p><\/blockquote><p>When you have done that, restart PHP using SSH.<\/p><p>On Apache, enter the command below to restart PHP.<\/p><pre class=\"wp-block-code\"><code class=\"\">&lt;script src=\"https:\/\/gist.github.com\/jennimckinnon\/a0a6d996d5d553aff58087cffc6c2f2b.js\"&gt;&lt;\/script&gt;<\/code><\/pre><p>For Nginx, enter the following:<\/p><pre class=\"wp-block-code\"><code class=\"\">&lt;script src=\"https:\/\/gist.github.com\/jennimckinnon\/ee58de4f502c3540e3f5cb81f60db64d.js\"&gt;&lt;\/script&gt;<\/code><\/pre><h3 class=\"wp-block-heading\">How to Install OPcache on Earlier Versions<\/h3><p>If your server is running on PHP versions 5.2, 5.3, or 5.4 you can manually install OPcache using the <a href=\"https:\/\/pecl.php.net\">PECL<\/a> command below:<\/p><pre class=\"wp-block-code\"><code class=\"\">&lt;script src=\"https:\/\/gist.github.com\/jennimckinnon\/f80d2fe73c1c1e0be5712e9bb8fe3fd1.js\"&gt;&lt;\/script&gt;<\/code><\/pre><p>Next, go to you <em>php.ini<\/em> file:<\/p><pre class=\"wp-block-code\"><code class=\"\">&lt;script src=\"https:\/\/gist.github.com\/jennimckinnon\/b4cbe5d0f924293fa29240c8ddf52517.js\"&gt;&lt;\/script&gt;<\/code><\/pre><p>You\u2019ll need to update your <em>php.ini<\/em> file with the following recommended settings:<\/p><pre class=\"wp-block-code\"><code class=\"\">&lt;script src=\"https:\/\/gist.github.com\/jennimckinnon\/a08541df21fa0a275b1306ec67b6f31c.js\"&gt;&lt;\/script&gt;<\/code><\/pre><p>You can often find your <em>php.ini<\/em> file in your site\u2019s file folder system. If you\u2019re not sure how to find it, contact your hosting provider.<\/p><h2 class=\"wp-block-heading\">Wrapping Up<\/h2><p>For many WordPress site owners, their server may already have the latest version of PHP installed. This means they already have OPcache automatically enabled to drastically speed up page load times for their site.<\/p><p>For those who have PHP version 5.2 to 5.4, you can manually install OPcache with the steps outlined above.<\/p>","protected":false},"excerpt":{"rendered":"<p>You can speed up your WordPress site so it\u2019s around three times faster or more with the OPcache PHP OPcode caching system. OPcache is a type of caching system that saves precompiled script bytecode in a server\u2019s memory called a cache, so each time a user visits a web page, it loads faster. Here\u2019s more [&hellip;]<\/p>\n","protected":false},"template":"","class_list":["post-5443351","caching_hub","type-caching_hub","status-publish","hentry"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>What is OPcache and How Do You Use It?<\/title>\n<meta name=\"description\" content=\"OPcache PHP opcode caching is a remarkable way to speed up your WordPress site by three times or more and here\u2019s how to quickly install it.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/wp-rocket.me\/wordpress-cache\/what-is-opcache\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What is OPcache and How Do You Use It?\" \/>\n<meta property=\"og:description\" content=\"OPcache PHP opcode caching is a remarkable way to speed up your WordPress site by three times or more and here\u2019s how to quickly install it.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/wp-rocket.me\/wordpress-cache\/what-is-opcache\/\" \/>\n<meta property=\"og:site_name\" content=\"WP Rocket\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/pages\/WP-Rocket\/631942253526829\" \/>\n<meta property=\"article:modified_time\" content=\"2023-05-10T13:34:47+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/wp-rocket.me\/wp-content\/uploads\/2023\/04\/wp-rocket-opcache-execute-code.png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@wp_rocket\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/wp-rocket.me\/wordpress-cache\/what-is-opcache\/\",\"url\":\"https:\/\/wp-rocket.me\/wordpress-cache\/what-is-opcache\/\",\"name\":\"What is OPcache and How Do You Use It?\",\"isPartOf\":{\"@id\":\"https:\/\/wp-rocket.me\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/wp-rocket.me\/wordpress-cache\/what-is-opcache\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/wp-rocket.me\/wordpress-cache\/what-is-opcache\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/wp-rocket.me\/wp-content\/uploads\/2023\/04\/wp-rocket-opcache-execute-code.png\",\"datePublished\":\"2023-04-11T10:34:40+00:00\",\"dateModified\":\"2023-05-10T13:34:47+00:00\",\"description\":\"OPcache PHP opcode caching is a remarkable way to speed up your WordPress site by three times or more and here\u2019s how to quickly install it.\",\"breadcrumb\":{\"@id\":\"https:\/\/wp-rocket.me\/wordpress-cache\/what-is-opcache\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/wp-rocket.me\/wordpress-cache\/what-is-opcache\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/wp-rocket.me\/wordpress-cache\/what-is-opcache\/#primaryimage\",\"url\":\"https:\/\/wp-rocket.me\/wp-content\/uploads\/2023\/04\/wp-rocket-opcache-execute-code.png\",\"contentUrl\":\"https:\/\/wp-rocket.me\/wp-content\/uploads\/2023\/04\/wp-rocket-opcache-execute-code.png\",\"width\":800,\"height\":800},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/wp-rocket.me\/wordpress-cache\/what-is-opcache\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/wp-rocket.me\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"WordPress Cache\",\"item\":\"https:\/\/wp-rocket.me\/wordpress-cache\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"What is OPcache and How Do You Use It?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/wp-rocket.me\/#website\",\"url\":\"https:\/\/wp-rocket.me\/\",\"name\":\"WP Rocket\",\"description\":\"Plugin d&#039;optimisation de sites WordPress\",\"publisher\":{\"@id\":\"https:\/\/wp-rocket.me\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/wp-rocket.me\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/wp-rocket.me\/#organization\",\"name\":\"WP Rocket\",\"url\":\"https:\/\/wp-rocket.me\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/wp-rocket.me\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/wp-rocket.me\/wp-content\/uploads\/1\/logo-wp-rocket-paypal-2.png\",\"contentUrl\":\"https:\/\/wp-rocket.me\/wp-content\/uploads\/1\/logo-wp-rocket-paypal-2.png\",\"width\":150,\"height\":41,\"caption\":\"WP Rocket\"},\"image\":{\"@id\":\"https:\/\/wp-rocket.me\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/pages\/WP-Rocket\/631942253526829\",\"https:\/\/x.com\/wp_rocket\",\"https:\/\/www.youtube.com\/channel\/UC1ozThXHd1IWIZ5wkshgp_Q\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What is OPcache and How Do You Use It?","description":"OPcache PHP opcode caching is a remarkable way to speed up your WordPress site by three times or more and here\u2019s how to quickly install it.","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:\/\/wp-rocket.me\/wordpress-cache\/what-is-opcache\/","og_locale":"en_US","og_type":"article","og_title":"What is OPcache and How Do You Use It?","og_description":"OPcache PHP opcode caching is a remarkable way to speed up your WordPress site by three times or more and here\u2019s how to quickly install it.","og_url":"https:\/\/wp-rocket.me\/wordpress-cache\/what-is-opcache\/","og_site_name":"WP Rocket","article_publisher":"https:\/\/www.facebook.com\/pages\/WP-Rocket\/631942253526829","article_modified_time":"2023-05-10T13:34:47+00:00","og_image":[{"url":"https:\/\/wp-rocket.me\/wp-content\/uploads\/2023\/04\/wp-rocket-opcache-execute-code.png"}],"twitter_card":"summary_large_image","twitter_site":"@wp_rocket","twitter_misc":{"Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/wp-rocket.me\/wordpress-cache\/what-is-opcache\/","url":"https:\/\/wp-rocket.me\/wordpress-cache\/what-is-opcache\/","name":"What is OPcache and How Do You Use It?","isPartOf":{"@id":"https:\/\/wp-rocket.me\/#website"},"primaryImageOfPage":{"@id":"https:\/\/wp-rocket.me\/wordpress-cache\/what-is-opcache\/#primaryimage"},"image":{"@id":"https:\/\/wp-rocket.me\/wordpress-cache\/what-is-opcache\/#primaryimage"},"thumbnailUrl":"https:\/\/wp-rocket.me\/wp-content\/uploads\/2023\/04\/wp-rocket-opcache-execute-code.png","datePublished":"2023-04-11T10:34:40+00:00","dateModified":"2023-05-10T13:34:47+00:00","description":"OPcache PHP opcode caching is a remarkable way to speed up your WordPress site by three times or more and here\u2019s how to quickly install it.","breadcrumb":{"@id":"https:\/\/wp-rocket.me\/wordpress-cache\/what-is-opcache\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/wp-rocket.me\/wordpress-cache\/what-is-opcache\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/wp-rocket.me\/wordpress-cache\/what-is-opcache\/#primaryimage","url":"https:\/\/wp-rocket.me\/wp-content\/uploads\/2023\/04\/wp-rocket-opcache-execute-code.png","contentUrl":"https:\/\/wp-rocket.me\/wp-content\/uploads\/2023\/04\/wp-rocket-opcache-execute-code.png","width":800,"height":800},{"@type":"BreadcrumbList","@id":"https:\/\/wp-rocket.me\/wordpress-cache\/what-is-opcache\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/wp-rocket.me"},{"@type":"ListItem","position":2,"name":"WordPress Cache","item":"https:\/\/wp-rocket.me\/wordpress-cache\/"},{"@type":"ListItem","position":3,"name":"What is OPcache and How Do You Use It?"}]},{"@type":"WebSite","@id":"https:\/\/wp-rocket.me\/#website","url":"https:\/\/wp-rocket.me\/","name":"WP Rocket","description":"Plugin d&#039;optimisation de sites WordPress","publisher":{"@id":"https:\/\/wp-rocket.me\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/wp-rocket.me\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/wp-rocket.me\/#organization","name":"WP Rocket","url":"https:\/\/wp-rocket.me\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/wp-rocket.me\/#\/schema\/logo\/image\/","url":"https:\/\/wp-rocket.me\/wp-content\/uploads\/1\/logo-wp-rocket-paypal-2.png","contentUrl":"https:\/\/wp-rocket.me\/wp-content\/uploads\/1\/logo-wp-rocket-paypal-2.png","width":150,"height":41,"caption":"WP Rocket"},"image":{"@id":"https:\/\/wp-rocket.me\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/pages\/WP-Rocket\/631942253526829","https:\/\/x.com\/wp_rocket","https:\/\/www.youtube.com\/channel\/UC1ozThXHd1IWIZ5wkshgp_Q"]}]}},"_links":{"self":[{"href":"https:\/\/wp-rocket.me\/wp-json\/wp\/v2\/caching_hub\/5443351"}],"collection":[{"href":"https:\/\/wp-rocket.me\/wp-json\/wp\/v2\/caching_hub"}],"about":[{"href":"https:\/\/wp-rocket.me\/wp-json\/wp\/v2\/types\/caching_hub"}],"wp:attachment":[{"href":"https:\/\/wp-rocket.me\/wp-json\/wp\/v2\/media?parent=5443351"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}