As a sign of our love for the PHP Renaissance, we rolled out public support for running your Drupal or WordPress site with PHP 7 on Pantheon. For those who have been following along at home, PHP 7 is a game-changing update to the programming language that runs a whopping 82% of the web. Packed with many new language features, PHP 7 provides much needed modernization to the PHP language which will help developers for years to come.
Perhaps the best feature of PHP 7 is a brand new version of the PHP engine called phpng. This engine was written to decrease memory consumption and increase performance. Early tests for both WordPress and Drupal show significant performance improvements. Moreover, both the Drupal and WordPress communities have done lots of work to ensure code compatibility with PHP 7.
This all sounds great to us here at Pantheon, so we decided to upgrade to PHP 7 for our main site (https://pantheon.io) which runs on Drupal 7. It was all pretty painless and we saw some significant performance improvements.
Making The Switch: Upgrading to PHP 7
As a first step to upgrading to PHP 7, I used Pantheon’s unique container architecture to create a Multidev environment for the “php7test” Git branch. By working in a separate environment, I can easily test new configuration (i.e. upgrade to PHP 7) and code without affecting the rest of the site’s workflow.
To actually perform the update to PHP 7, I needed to create a pantheon.yml file in the root of my codebase. For those who are familiar with our Quicksilver Platform Hooks, pantheon.yml is the place where you can define platform hooks and provide advanced site configuration (like the PHP and Drush versions). These configurations happen on a per environment basis, so it is easy to test PHP 7 in a Multidev environment.
As part of the upgrade to PHP 7 for Drupal 7 sites, it is important to upgrade your version of Drush. The default version of Drush that runs with Drupal 7 sites is Drush 5 which isn’t fully compatible with PHP 7. Luckily, it is only one additional line in your pantheon.yml to set your version of Drush to Drush 8, the latest and greatest, which is compatible with PHP 7. Here is my pantheon.yml with the PHP and Drush version specification:
Testing And Upgrading
After getting the site running with PHP 7, I immediately noticed a number of PHP errors being generated on each page load. Although a lot of work has gone into Drupal 7 core to make it PHP compatible, there are bound to be edge cases and not all contrib modules have been upgraded for PHP 7 compatibility.
In my case, I realized that the PHP errors were actually coming from two contrib modules we were running on the site: Nodequeue and CTools. After investigating the errors on Drupal.org, I quickly realized that others had already reported them and the latest version of both modules contained the appropriate upgrades to make the modules work with PHP 7.
Your mileage may vary with PHP 7 compatibility for the modules (or plugins) you use, but in many cases a new version may be available to help you. If a new version is not available, writing (or testing) a patch to upgrade the code to PHP 7 is pretty easy. Just follow this handy guide for upgrading code to PHP 7 and contribute your upgrade back to your favorite Drupal or WordPress project.
[Related] How Agencies Benefit from Pantheon High Performance Web Hosting
Performance Testing: Get Me the Data
While it felt good just to get the site running PHP 7, I wanted to also figure out how the upgrade affected the site performance. To do this, I need to set up a quick performance test that I could run on both the old version (PHP 5.3) and the new version (PHP 7). Since I had some familiarity with Load Impact from my work integrating it with Quicksilver, I decided to set up the test there.
Load Impact has a Chrome Extension that allows you to record a user scenario which can be replayed as part of a performance test. I recorded a quick scenario that simulates a user going to the Pantheon site, logging in as an authenticated user, and browsing through a number of blog posts and landing pages. Doing the test as an authenticated user (check out this post for information on how use Load Impact with a Drupal user account) was important to bypass the Varnish cache so I could get better data on how Drupal was performing.
I then ran that test on the new PHP 7 environment and also created a new Multidev environment which was just a copy of the live site (but without the current live traffic so I could get an apples to apples comparison). I chose to test 100 “virtual users” for 15 minutes on both sites, but any sufficient traffic should work. For even better results, you can record multiple user scenarios to test different kinds of users doing different things on the site.
PHP Performance By Version: Show Me the Data
While Load Impact provides some tools to determine how fast the site is performing, those tools pale in comparison to the power of New Relic. Not only does New Relic run directly on the Pantheon server (so it knows a lot more about what is going on with the application), but it has much more sophisticated tooling to review the data. Best of all, every site on Pantheon comes with New Relic Pro included. You just need to enable it to start recording and reviewing data. Here is what I came up with after running the test on the old (PHP 5.3) version and the new (PHP 7) version:
Pantheon.io on PHP 5.3 (Load Impact Performance Test)
Pantheon.io on PHP 7 (Load Impact Performance Test)
As you can see, there is a significant (64%) improvement in speed between the old version and the new version of the site. This was a pretty significant (theoretical) improvement for only a few lines in a YAML file and updating two modules that I had to do anyway.
PHP Performance By Version: Show Me the (Real World) Data
The performance tests that we ran above help to provide good benchmarking for PHP 7, but they are just theoretical tests. As Josh has talked about on #NoBSBenchmarks, the best performance data is going to come from real world experience. Here are two snapshots from our site showing performance data. One was made after we upgrade to PHP7 and the other was made a week before when we were still running PHP 5.3. Similar to the results we found from our performance testing, we saw a significant (68%) improvement in app server speed:
Pantheon.io on PHP 5.3 (Real World Data)
Pantheon.io on PHP 7 (Real World Data)
While your mileage will vary depending on the particular traffic patterns of your site, I can certainly certainly say this was probably the easiest and most straightforward performance optimization that I ever made. If you are running a WordPress or Drupal site, check out if your site can run PHP 7 today!