WordPress Performance: Modernizing PHP and Opcode Cache
Emily Miller interviews Scott Walkinshaw as he gives advice for web teams on updating PHP and talks about the benefits of using an Opcode Cache.
Join the DZone community and get the full member experience.Join For Free
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:
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.
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.
Opinions expressed by DZone contributors are their own.