WordPress Performance: What to Know about Modernizing PHP & Opcode Cache

Website performance isn’t inherent—it requires a good grasp on best practices and a willingness to invest time and resources to achieve optimal results. Fortunately for the WordPress community, performance has been a hot topic as of late, and many are beginning to discuss and document what it takes to run WordPress at scale.

There are known, widely-accepted best practices for successfully running high-traffic WordPress implementations, one of which is running modern PHP with an Opcode Cache. We caught up with Scott Walkinshaw of Roots for some expert insight into modernizing PHP and the importance of using an Opcode Cache:

What advice would you give web teams on updating PHP?

Scott: Test. Test. Test. Updating the programming language your application runs on is a big deal. That being said, PHP makes this as straight-forward as possible. There are guides to backwards incompatible changes for every major version upgrade:

5.2.x > 5.3.x: http://php.net/manual/en/migration53.incompatible.php

5.3.x > 5.4.x: http://php.net/manual/en/migration54.incompatible.php

5.4.x > 5.5.x: http://php.net/manual/en/migration55.incompatible.php

5.5.x > 5.6.x: http://php.net/manual/en/migration56.incompatible.php

5.6.x -> 7.0.x: http://php.net/manual/en/migration70.incompatible.php

Thankfully PHP does a good job reducing the number of breaking changes. The majority of code should work seamlessly on most versions. The biggest changes were probably on 5.3 and 5.4.

WordPress is compatible out of the box from PHP 5.2 to PHP 7.0 as long as you're on a newer version (4.4+). It's WordPress' job to worry about their own core code compatibility. As a web team running a WordPress application, it's your responsibility to ensure all of your own custom code and all 3rd party plugins and themes work as well.

The best way to do this is to upgrade your PHP version on developer machines and staging servers first to test. Never just upgrade PHP on your production servers and assume it will work. Hopefully you have a test suite you can run to detect regressions. Another good strategy is to have an error monitoring service so you can find new errors and compare error rates between PHP versions.

[Related] How Agencies Benefit from Pantheon High Performance Web Hosting

Just how bad is running outdated PHP for performance?

Scott: Most developers know that programming languages add features and fix bugs in new versions. But most languages get faster and improve performance over time as well. PHP 5.2 was released in 2006. In the 9 years between 5.2 and 7.0, PHP has gotten much, much faster. Using an older version (such as 5.2) is like choosing to stick with an original iPhone instead of the latest 6S. Many PHP 7.0 benchmarks have shown up to 2x performance improvements for WordPress sites.

What are the benefits of using an Opcode Cache?

Scott: Opcode cache simply saves PHP from doing a lot of work making your sites faster. Take WordPress for example: on a single request PHP is loading, parsing, and compiling thousands of scripts (files) into bytecode. Without any opcode caching, this happens on every request which is very inefficient.

With Opcode caching (like the now built-in OPcache in 5.5+), PHP stores this compiled bytecode. That means on subsequent page requests, PHP can skip a lot of work leading to huge performance gains.


Want more? Check out our latest SlideShare, Level Up: 5 Expert tips for Optimizing WordPress Performance, for five ways you can more than double your site’s speed and responsiveness. Or learn how you can improve WordPress hosting performance with Pantheon.

Topics Development, Speed & Performance, Testing & Optimization, WordPress