How Enabling OpCache Makes WordPress Faster


There are a number of optimizations that you can make to your site in order to increase its power to give you the results you want. Some of these have been explored in recent articles or will feature soon on our blog.

Many of these optimizations involve some kind of caching, such as page caching and the use of CDNs. Another type of caching that works at the level of the PHP code that powers all WordPress sites is PHP opcode caching. This particular optimization is very simple to implement and usually provides a significant decrease in overall latency for you site. Depending on the complexity of your site, it is possible that this optimization could double your site speed.

How does it work?

From the official PHP documentation:

“OPcache improves PHP performance by storing precompiled script bytecode in shared memory, thereby removing the need for PHP to load and parse scripts on each request.”

Take a look at this diagram:

The basic principle here is reuse. Usually, a PHP script will be compiled into opcodes at runtime each time the script executes. This requires time and computing power, which can be saved if the results are reused. What OPcache does is save the results of the first compilation into cache memory so that when they are needed again, they are accessible at very high speeds and the compilation step is bypassed.

As well as this caching functionality, OPcache also performs a lot of optimisations within the code itself, such as replacing $i++ with ++$i when the return value isn’t used, for example.

How to Enable PHP OPcache on your server

To enable PHP OPcache, you will need to edit your php.ini file.

As a minimum you will need the following lines:

zend_extension=full/path/to/ (linux) (Linux/Mac)
zend_extension=full/path/to/php_opcache.dll (Windows)
Determines if Zend OPCache is enabled

NB Don’t forget to restart your web server for changes to take effect.

For a full list of possible configuration settings, check out the documentation here.


The PHP OPcache extension is bundled with PHP version 5.5.0 and later. This means that it if you are following guidelines and using PHP version 7 or greater, it should be available. However, It is important to note that not all hosting providers offer PHP OPcache as part of their service. If this particular optimization is essential to you then you will need to choose a provider that does.

In order to get PHP OPcache enabled and configured on your site, you should talk to your developer and/or hosting provider. The process is fairly straightforward, but there are a couple of “gotchas” to look out for. For example, depending on configuration settings, changes to PHP scripts may or may not be automatically noticed. If they are not, then you will need to remember to flush the opcode cache when changes are made to your PHP scripts.


If you have a large website that with high volumes of traffic, you should definitely use the PHP opcode cache. It is a simple way to gain a dramatic improvement in your site's performance.

Why Should You Use an Asset Cache with WordPress?

There are many good reasons to use a CDN (Content Delivery Network) for asset caching. This article explores these reasons under separate headings for ease of reference.

The main principle we are discussing here is that by using a CDN for serving static assets, the assets are served closer to the client. The decrease in physical distance reduces the latency involved in loading these assets and since an average website is composed of up to 90% static content, page load times are therefore significantly improved.

User Experience

To put it bluntly, if we are talking about the world of business, then

While there are many other considerations, from the point of view of many clients, this is the primary issue, and it is the one we will explore first.


There are some commonly quoted statistics found on the internet about the relationship between page load speed and conversions or at least user satisfaction. However, these statistics are unreliable and often quoted out of context.

What we can say for sure is:

  • If people have to wait too long for a page to load, they will eventually give up and look elsewhere. Defining “too” long is tricky, but it is clear that “quicker is better.”
  • Improving page load time is very likely to lead to more conversions.

Less downtime

Failover is "a procedure by which a system automatically transfers control to a duplicate system when it detects a fault or failure." This is a very good thing. Using a CDN means that your site's static files are replicated across a global network of servers, meaning that a problem in one server will not cause major problems for your users as the content is simply served from another server in the network.

Better content due to higher capacity

Having faster access to assets also means that serving larger files becomes more viable. This means for example that retina-ready images and high definition video can now be used without compromising page load times to the point where the increase in quality of assets is negated by a corresponding lag in display them.

Client experience

Improved SEO

Put simply, websites with faster response times tend to end up higher in search results. This is because search providers want to provide their users with the best experience possible to maintain and increase their user base. Using a CDN to serve your site's assets will keep your customers and the search providers happy.


A CDN can help with your site's security in a number of ways. It will help to filter legitimate traffic from less desirable visitors such as "bad bots." It will also help to protect you from Distributed Denial of Service attacks (DDoS) by absorbing malicious traffic across a global network of servers. CDNs have specialized algorithms able to identify malicious traffic and prevent it from causing harm.

Developer advantages

As a developer, a lot of time is often spent on tasks such as content minification and combination, image optimization and content caching. This can involve installing, configuring and understanding a wide range of tools, many of which come into fashion and go out again in a relatively short time span. Wouldn't it be great if much of this part of the development process could be "outsourced" to an external service which you trust, leaving you to focus on creating great functionality and visually stunning websites?

From a client's point of view, this means paying for less development time since the developers are not bogged down with all of these optimisation tasks, which are now handled externally.


The main reason people think of when considering using a CDN for serving assets is site speed. This is the primary benefit and the most obvious one for users of your site. However, there are other benefits for users and clients too, as discussed in this article.

Please note that MOZR handles Asset Caching automatically and leverages the world’s best CDN.