WinningWP content is free to all. If you make a purchase through referral links on our site, we earn a commission (learn more).
Tags – , ,

What is PHP 7 and How to Start Using it With WordPress?

WordPress Deals

PHP 7 is one of the most significant updates in the history of a server-side software that powers more than 82% of the internet, and, in this guide, we’ll discuss the ins and outs of using it with WordPress.

We’ll look at PHP 7’s incredible advantages, and help you to understand the importance of adhering to the recommended minimum version (5.6). You’ll also learn how to check whether your WordPress site is ready for PHP 7, and measure the pros and cons of upgrading to this new version.

At the end of this guide, you’ll be equipped with a firm understanding of PHP, and convinced enough to update to the recommended minimum — or maybe even take the next step to PHP 7!

Let’s get started…

A Beginner’s Guide to PHP — What Is PHP?

For those of you who are absolutely new to the topic, PHP is a server-side scripting language designed to generate HTML pages upon request.
Think of it as a simple three-step process:

  • Input: You enter a set of commands written in the form of a PHP script, as the input to the PHP Engine.
  • Processing: The PHP Engine executes the script on the server.
  • Output: The output is an HTML page that’s rendered by the web browser.

In the three-step process described above, we can identify a few components.

  1. The PHP script(s)
  2. PHP Engine
  3. Server
  4. Output HTML

Now, let’s see how they relate to a typical WordPress environment.

Components of a typical PHP Environment

1) PHP Scripts: WordPress is essentially a vast, organized collection of code written in multiple scripting languages, such as PHP, JavaScript and CSS, with the primary one being PHP. It’s what gives WordPress its dynamic nature.

2) PHP Engine: Think of it as the central component that executes the instructions laid down in the PHP script — doing so with the help of the server it’s running on. The PHP Engine is one of the most crucial components, and affects the speed, performance and reliability of a website. It’s also the central topic of our discussion!

3) Server: This is the remote computer, also known as the ‘web host’, where your WordPress site is hosted. If there were a web host without PHP installed, WordPress would not run on it.

4) Output HTML: Every time a WordPress website is loaded, the PHP engine is summoned. Scripts are executed by the PHP engine using the server, and the final (or output) HTML is exported to the visitor’s web browser. And that’s what completes the process.

What Is PHP 7?

Now that we’re clear on what a PHP script is, let’s talk about the PHP Engine. For the remainder of the article, we’ll use the terms ‘PHP engine’ and ‘PHP’ synonymously.

PHP 7 is a PHP engine that was launched in December 2016, and carries a plethora of new features, performance improvements and security enhancements. As with every good lesson, let’s start with a bit of history.

A Brief History of PHP

PHP was released in 1994 as a scripting language by Rasmus Lerdorf in an effort to create a tool that would make updating his personal homepage easy. *Little did he know that this side-project would evolve to power more than 82% of all websites — including biggies such as *Facebook and WordPress.

Over the years, PHP has had a couple of releases. The first one being in 1995, followed by version 2.0 in 1997. Version 3.0 was released in 1998 followed by version 4.0 in 2000.

Is it the anticipation that makes PHP 7 special?

illustration of 12 years time taken to release php 7

This is where things started to get interesting. PHP version 5 was released four years later in 2004. It went on to have multiple iterations — so much so that the committee decided to skip version 6 and jump to version 7. To put things into perspective, the first iteration of PHP 5 was version 5.0, released in 2004. Its last iteration, PHP 5.6, was released ten years later in 2014.

Two years down the line, PHP 7 came along — the most promising release of PHP to date. In essence, the world had to wait a good 12 years to get their hands on PHP 7.

Performance Improvements in PHP 7

The wait did not go to waste. PHP 7 came with a truckload of performance and security improvements. Let’s dig into each performance improvement, backed by solid benchmarks.

1) Massively Improved Bandwidth (requests per second)

php 7 advantages in WordPress higher bandwidth

PHP 7 performed nearly twice as well as PHP 5.6, running WordPress 4.1.1.

php7 vs php 5.6 in WordPress performance benchmark

In the chart above, we can see almost 2.18 times the number of requests per second at less than half the latency.

2) Lower Latency for Concurrent Users

php 7 advantages in WordPress lower latency

Latency is the amount of time elapsed between the first request and the first response between the server and client. The lower the latency, the better the service. Let’s check out how PHP 7 handles it.

php7 vs php 5.6 in WordPress latency concurrent users

We’ve taken three data points based on the number of concurrent users for each PHP engine.

  1. The orange bars represent the latency when ten people are simultaneously using your site.
  2. The blue bars are for double (i.e. 20 concurrent users).
  3. The pink bars are for 40 simultaneous users.

In all cases, PHP 7 knocks its predecessors out of the park.

*All of this in the *exact same hardware! This means that if you were to upgrade to PHP 7 with all the necessary compatibility checks in place (more on this later), you should see a two-fold increase in performance.

3) WordPress 4.0+ Releases are Optimized for PHP 7

php 7 advantages in WordPress better compatibility with wordpress

WordPress 4.0 itself has been fine-tuned to leverage PHP 7’s latest features. According to Zend, it has almost double the performance on the same hardware, compared with its predecessor, WordPress 3.6.

php7 WordPress 3.6 vs 4.1 performance improvement

In the chart above, we see that there’s a two-fold performance improvement in a major WordPress update. This benchmark is irrespective of the version of PHP. Rather, it is an indication that the WordPress community is continuously optimizing code for the upcoming versions of PHP.

4) 75% Fewer Instructions, Same Result

php 7 advantages in WordPress memory optimization

PHP 7 also has a killer instruction set. It’s outrageously optimized for executing the same task in fewer instructions. For example, one WordPress request on PHP 5.6 executes in 100 million CPU instructions. Whereas in PHP 7, the same request is executed in 25 million CPU instructions. That’s a 75% reduction in the number of commands required to do the same job!

5) Significant Performance Gains

php 7 advantages in WordPress superior performance

Jason Cosper, resident nerd at WP Engine, loves messing with the latest PHP engines to see which ones work best.

php 7 advantages in WordPress php 5.5 vs php 7.0

In one of his experiments, he found PHP 7 to be arguably 6.6 times faster than PHP 5.5 — running WordPress 4.3.1 and bbPress.

State of WordPress PHP in Q1 2017

Now that we have a functional understanding of the benefits of PHP 7, let’s take a look at how many WordPress users are using it.

state of WordPress php 2017 q1

The Good: According to the official WordPress stats, 9% of the WordPress community has upgraded to PHP 7 as of 20 April 2017.

The Okay: Around 40% of WordPress users are using PHP 5.6. This is relatively good news, since PHP 5.6 gets security support until 31 December 2018.

The Ugly: However, the really bad news is more than 50% of the active WordPress sites use a version of PHP older than 5.6, which exposes all these sites to severe vulnerability issues.

  • PHP 5.4 has not been patched since 2015.
  • And PHP 5.5 has not been patched since 2016.
  • If you’re using a version older than 5.6 (more on how to check your PHP version later), please update your PHP version immediately.

A Beacon of Hope

yoast seo php 5 and php 7 battle

Joost de Valk, founder of Yoast SEO — a WordPress SEO plugin with over than 3 million active installations — decided to do something about this. To quote from the original article:

As of Yoast SEO 4.5, we’ll start showing a notice on the WordPress dashboard to administrators of sites running on PHP 5.2. This notice will be big, ugly, and non-dismissible. In this notice, we will explain why the administrator should upgrade the PHP version of the site.

WordPress and Outdated Versions of PHP

dangers of outdated php illustration

At this point, it’s important to point out that WordPress will continue to support older versions of PHP. This does not mean you can sit back and relax. It’s in our best interest to upgrade to 5.6 — if not PHP 7.

php 5.x and php 7 support timeline

If you’re on PHP 5.6, there are a couple of things coming your way soon:

  1. According to the official PHP support timeline, PHP 5.6 would get official support until 17 Jan 2017. That’s ended.
  2. In better news, PHP 5.6 would get security support until 31 December 2018.
  3. Of course, you’ll still be missing out on all the performance enhancements you could get for absolutely zero investment.

Switching to PHP 7 — Is It Worth It?

Now that we have a firm understanding of the various advantages of PHP 7, let’s address the crucial question: Should you switch to PHP 7?

The method for arriving at any decision should be based on logic. We’ll look at tackling these three basic questions:

1. What Are the Advantages of Switching to PHP 7?

php 7 advantages

We’ve covered five points backed by benchmarks from around the web. All of them point to a host of benefits, and to a resounding yes when it comes to the decision to switch.

2. Are Your WordPress Theme and Plugin(s) Compatible with PHP 7?

php 7 compatibility issues

Just because WordPress is compatible with PHP 7 (and has backward compatibility with PHP 5.6), does not mean all its themes and plugins are. You may use a custom-built theme or plugin that has features that are deprecated in PHP 7. You may also use a plugin from the WordPress repository that’s not been updated for a while. What’s the solution?

3. How Can You Check if Your WordPress Site Is Ready for PHP 7?

php 7 challenges

Luckily, the generous developers over at WP Engine have created a rather awesome plugin that solves this very problem.

php compatibility checker WordPress plugin by wpengine

Introducing the PHP Compatibility Checker: A plugin that scans your WordPress code base and active theme plugins looking for known compatibility issues.

PHP Compatibility Checker

Supported PHP versions of the PHP Compatibility Checker Plugin

You can check for compatibility issues for five distinct versions of PHP, ranging from 5.3 to 7.0.

php compatibility checker WordPress plugin test results

(click to enlarge)

The compatibility issues (if found) are categorized into errors and warnings. The plugin will list the file and line number of the offending code, along with information as to why that code is incompatible with the chosen version of PHP.

However, there are a few limitations:

  1. The plugin cannot detect runtime compatibility issues, since it doesn’t execute any of the existing themes and plugins.
  2. It relies on WP-Cron to scan files in the background, so WP-Cron must be enabled and working on the server.
  3. Occasionally, false positives are reported since the plugin cannot detect unused code paths that may be used for backwards compatibility.

list of supported plugin checks by php compatibility checker

Sample list of plugins supported by PHP Compatibility Checker.

All in all, it’s a pretty neat plugin that can tell you whether or not your WordPress stack is prepared for the upgrade!

4. What Are the Dangers of Not Switching to PHP 7?

php 7 pitfalls

The following three points explain the disadvantages of not upgrading to the recommended PHP 7. They also highlight some of the possible dangers of not upgrading to the required minimum version, PHP 5.6.

4.1 Performance Drop: First off, you’d miss out on at least a two-fold increase in performance without investing a single dime. And guess what? If you’re on PHP 5.2, it’s reported to be 400% slower than PHP 7!

4.2 Security Issues: PHP 5.x had a plethora of vulnerabilities that were duly patched with the newer versions. In fact, 2016 was actually a record year for PHP security vulnerabilities, with more than 100 issues reported, ranging from Denial of Service (DoS) to memory corruption, malicious code execution, and so on.

To give you an idea of how bad the situation is, PHP 5.4 hasn’t been patched since 2015, and it’s no longer supported. And yet 21% of WordPress users still use PHP 5.4! If you’re a part of that group, please update to 5.6 today.

4.3 Broken Plugins: Using an older, unsupported version of PHP creates plugin conflicts. One of the most prominent errors is the ‘unexpected T_Function‘, as seen below.

outdated version of PHP causes WordPress conflicts

Screenshot of support thread of the Content Locker plugin

The above screenshot is a support query for the Content Locker plugin. The author clearly mentions that the minimum version of PHP required for the plugin to work is 5.4.

5. Success Stories

PHP 7 success stories

It’s always encouraging to see how various organizations across the globe are benefiting from the upgrade.

5.1) A Fortune Saved for Badoo

Our first example is dating app Badoo, which has managed to save over $1 million by upgrading to PHP 7. How? Simple! PHP 7 reduced the amount of computing power required to accomplish the same task. Thus, fewer servers were required to do the same job, which ended up freeing up some 300 servers!

5.2) Major Performance Boost for Clinton Electronics

Our second success story comes from a WP Engine client, Clinton Electronics. In a nutshell, they wanted a dynamic ecommerce store with fast load times. The chosen stack was WordPress, along with WooCommerce. The agency they were working with chose WP Engine as the managed WordPress hosting provider, which, in turn, recommended PHP 7. This upgrade ultimately managed to reduce the website’s load time by as much as 60%!

How to Switch to PHP 7 with WordPress?

switching to php 7 illustration

First off, ensure your current WordPress stack is compatible with PHP 7 using the PHP Compatibility Checker plugin. Once the plugin gives you a green light, proceed with the upgrade.

  • If you’re using shared WordPress hosting, such as Bluehost, you can update your version of PHP in four simple steps. Almost all shared WordPress hosting providers come with a cPanel or a custom access panel wherein you can change the version of PHP.
  • If you’re using a managed WordPress hosting provider, such as WP Engine, switching to PHP 7 is a piece of cake — reach out to their support, and they’ll have it done in a jiffy.
WPEngine PHP FAQ page Retrieved 26 Apr, 2017

WPEngine PHP FAQ page Retrieved 26 Apr, 2017

WP Engine PHP FAQ page, retrieved: 26 April 2017

Good news for WP Engine users is that the minimum allowed version of PHP is 5.6, according to their FAQ page.

Why WP Engine? There are a host of benefits that make WP Engine even more attractive:

  1. Innovative WordPress technology.
  2. Blazing fast servers capable of handling hundreds of millions of requests per day.
  3. Hardcore security with advanced DDoS protection.
  4. Superior support.

They’ve been in the business for a couple of years now, and have won over top brands, such as National Geographic and AMD. What I personally like most about WP Engine is their culture of giving back to the community — be it sponsoring WordCamps, hosting events, or building awesome free plugins such as the PHP Compatibility Checker.

If you’re considering an upgrade, or looking to change your current hosting provider, we would highly recommend WP Engine as your managed WordPress hosting provider, with plans starting at $29 a month.

Wrapping Up

Let’s quickly recap all that we’ve learnt so far:

  1. PHP powers 82% of the internet, powering sites such as Facebook and WordPress.
  2. The recommended minimum version of PHP is 5.6 — anything below that is a big no-no!
  3. PHP 7 has significant improvements in terms of performance, security and features — it easily increases WordPress’ performance by 2x with zero additional hardware.
  4. Switching WordPress to PHP 7 brings home a host of benefits without any investment.
  5. However, before switching, you need to ensure your WordPress setup is ready to be upgraded to PHP 7 using the PHP Compatibility Checker plugin.
  6. Shared hosts such as Bluehost support PHP 7, but it needs to be enabled manually.
  7. Managed WordPress hosts such as WP Engine have rock-solid compatibility with PHP 7.

At the end of the day, PHP is continuing to improve with every release. If you’re using WordPress along with only the popular plugins, you could gain a lot by upgrading to PHP 7. However, if you’re using a lot of custom or infrequently updated plugins, it’s perhaps best to hold on for a few more months before upgrading. However, it’s imperative that you use PHP 5.6 and nothing below that!

Already using PHP7 with WordPress? Thoughts?

By Sourav Kundu

A technology enthusiast in general, Sourav enjoys learning and writing about WordPress, and is interested in marketing, psychology and all things digital. He can be reached on Twitter.
Comments (policy)

Leave a Reply

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

All comments are held for moderation. We'll only publish comments that are on topic and adhere to our Commenting Policy.