WordPress on PHP 7.1

Mattias Geniar, Thursday, March 9, 2017

Since I care about performance, features and security, I decided to upgrade my webservers' PHP version from 5.6 to the latest PHP 7.1.2. I run mostly WordPress websites, so what's the impact of such a PHP version upgrade on WordPress?

At the time of writing, PHP 5.6 is in extended support, meaning it'll still get security updates, but no more bugfixes. The PHP 7.x release is the only actively support PHP version, of which PHP 7.1 is the latest version.

Let's start with some benchmarks.

Performance improvements with WordPress on PHP 7.1

First, some numbers, before I go all graph on you.

I took a fairly big page on this blog (and a popular one, too) to run the ab benchmark against: Google’s QUIC protocol: moving the web from TCP to UDP.

The goal is to execute 300 requests as quickly as possible, 2 at a time (concurrency = 2).

$ ab -c 2 -n 300 https://ma.ttias.be/googles-quic-protocol-moving-web-tcp-udp/

For the sake of this test, I decided to disable the static HTML caching, I want the raw PHP performance.

The results (averaged out, as I did the test several times) -- lower is better;

  • PHP 5.6: 94.3 seconds
  • PHP 7.1: 74.5 seconds (22% faster)

For comparison, I also took a Laravel application I made called DNS Spy and did the same benchmark.

  • PHP 5.6: 40.1 seconds
  • PHP 7.1: 30.2 seconds (25% faster)

It's safe to assume PHP 7.1 is considerably faster than 5.6 with about 25% raw speed improvements. And this isn't counting the memory savings you get, because the 7.x branch is much more memory efficient than 5.6 (I just didn't accurately measure that to benchmark).

In a graph, the above timings are actually rather boring. In absolute numbers, it's the difference between an average response time of 350ms vs 250ms. Yes, it matters, but in a graph with spikes, it doesn't say much.

Things get more interesting when you look at pages that take more time to load, like the RSS feed in WordPress. This graph shows the RSS timings for the posts and the comments (2 separate requests).

In that graph, it's gone from an average response time of 610ms (for both feeds) to 280 ms. That's a 200% speed improvement over PHP 5.6!

WordPress compatibility on PHP 7.1

The million dollar question is, of course: what did I break by upgrading?

So far: nothing.

But I should point out, most of my blogs have a very limited set of plugins and are simple in both design and functionality.

WordPress itself will run, as a minimum requirement, on PHP 5.2.4 or higher. That's a bug, not a feature. That old PHP version should've been buried and forgotten a long time ago.

But there's an upside, too: because they still support PHP 5.2.x, they can't use any of the newer features of PHP 5.3 (namespacing), PHP 5.4 (anonymous functions), 5.5 (OPCache instead of APC), ... so WordPress core is really boring PHP. That boring PHP will run on pretty much any PHP version, including the 7.x branches.

Plugins are a different matter: popular plugins, like the Yoast SEO Plugin, will actively begin to encourage users to upgrade to a later PHP version. This is excellent news. It also means plugins are going to be your risk when upgrading PHP versions, as their supported PHP versions may vary.

Functionality testing on PHP 7.1

Limited, but this is what I tested (by writing this post) and what still works, flawlessly;

  • Post writing & editing
  • File uploads
  • GUI & text editor
  • Dashboard, WordPress statistics & widgets
  • Plugin updates & auto-updates

Seems to be the biggest pieces of functionality, to me.

PHP warnings & errors

This won't show in the GUI, but your error logs from PHP-FPM may start to show things like this;

$ tail -f php/error.log
[09-Mar-2017 20:41:54 UTC] PHP Warning:  A non-numeric value encountered in /var/www/vhosts/ma.ttias.be/htdocs/wp-content/plugins/.../Abstract.php on line 371
[09-Mar-2017 20:42:17 UTC] PHP Warning:  A non-numeric value encountered in /var/www/vhosts/ma.ttias.be/htdocs/wp-content/plugins/.../Abstract.php on line 371
[09-Mar-2017 20:43:54 UTC] PHP Warning:  A non-numeric value encountered in /var/www/vhosts/ma.ttias.be/htdocs/wp-content/plugins/.../Abstract.php on line 371

Since I have no interest in maintaining plugins and lack the time to learn how SVN works again to submit a PR or patch, I simply disabled warnings in PHP.

Conclusion: WordPress + PHP 7.1 = ❤️

For me, it just works. No quirks, faster performance & a fully supported PHP version.

What's stopping you from upgrading?



Hi! My name is Mattias Geniar. I'm a Support Manager at Nucleus Hosting in Belgium, a general web geek, public speaker and podcaster. Currently working on DNS Spy. Follow me on Twitter as @mattiasgeniar.

I respect your privacy and you won't get spam. Ever.
Just a weekly newsletter about Linux and open source.

SysCast podcast

In the SysCast podcast I talk about Linux & open source projects, interview sysadmins or developers and discuss web-related technologies. A show by and for geeks!

cron.weekly newsletter

A weekly newsletter - delivered every Sunday - for Linux sysadmins and open source users. It helps keeps you informed about open source projects, Linux guides & tutorials and the latest news.

Share this post

Did you like this post? Will you help me share it on social media? Thanks!

Comments

Muhammad Waqas Saturday, March 11, 2017 at 05:52

The reason why WP is reluctant to increase minimum requirement to PHP 7 is cheap shared hostings. And the “not tech savvy” users who don’t give a damn even about whats is WP made of. All they want is their site running somewhere. Clearly WP don’t want to lose that userbase.

Its similar to developers trying to add polyfills for IE 8.

Reply


Mattias Geniar Saturday, March 11, 2017 at 10:30

The reason why WP is reluctant to increase minimum requirement to PHP 7 is cheap shared hostings.

This is what always surprised me. We also offer shared hosting, and we actively push for newer PHP versions. It saves us CPU cycles and memory and we can run more shared hosting sites on a single server.

Even the hoster benefits, perhaps most of all!

Reply


Peak Design Monday, March 13, 2017 at 13:48

Definitely worth a share! Thanks for this Mattias Geniar :-)

Reply


Dusan Monday, March 13, 2017 at 18:11

Hi,
Did you have installed and configured opcache on php 5.6?

Tnx

Reply


Mattias Geniar Wednesday, March 15, 2017 at 14:09

Hi,

Yes, the exact same PHP OPCache settings on 5.6 and 7.1;

$ cat opcache.ini
; Enable the opcache extension module
; Zend Extension
zend_extension=/usr/lib64/php/modules/opcache.so

; Custom settings
opcache.enable_cli=0
opcache.fast_shutdown=1
opcache.interned_strings_buffer=16
opcache.max_accelerated_files=4000
opcache.memory_consumption=192
opcache.revalidate_freq=0
opcache.save_comments=1
opcache.validate_timestamps=1

These are similar to my recommended PHP OPCache settings.

Reply


Dusan Friday, March 17, 2017 at 03:40

Thanks for the response, Mattias.
( Asked because many benchmarks earlier were 5.6 without vs 7.0 with. And, I presumed that you made a test with it, I needed to ask. No relationship with WP though. :) Thanks again )

Reply


Leave a Reply

Your email address will not be published. Required fields are marked *