Performance & Security

PHP 7 Speed Gains: What Upgrading Does for Your Site

PHP 7 is the biggest speed improvement PHP has had in years. Here is what it changes, what it means for your site and how to upgrade without breaking anything.

Quick answer: PHP 7, released in December 2015, rebuilt the core of the PHP engine. In benchmarks published by the PHP developers and many hosting companies, common applications such as WordPress handle far more requests per second and use noticeably less memory than on PHP 5.6. For a site owner that means faster page generation, especially on uncached pages such as the admin, search and checkout, and more headroom on the same server. The catch is compatibility: some older plugins, themes and custom code use features PHP 7 removed, so test on a copy of the site before switching.

Most WordPress, Drupal and Magento sites run on PHP. Every time a page is not served from cache, PHP runs your CMS code, queries the database and builds the HTML. How quickly it does that affects how fast your site feels and how many visitors your server can handle at once.

Why PHP 7 is faster

PHP 7 grew out of a project called PHPNG (“next generation”), which reworked how the engine stores and handles data internally. The main changes:

  • Leaner data structures. Values, arrays and objects take up less memory, so PHP spends less time allocating and copying them.
  • Fewer memory allocations. Much of the overhead in PHP 5 came from constantly asking the system for small chunks of memory. PHP 7 does this far less.
  • Faster function calls and arrays. Common operations used everywhere in CMS code are quicker.
  • Better use of the opcode cache. OPcache, bundled with PHP since 5.5, works well with the new engine.

You do not need to change your code to get these gains. If your code runs on PHP 7, it simply runs faster.

What it means for a WordPress site

Faster uncached pages

Page caching hides PHP speed for most anonymous visitors, because they receive a stored copy of the page. But many requests cannot be cached:

  • Logged in users, including you in the dashboard.
  • Shopping carts, checkouts and account pages in WooCommerce.
  • Search results.
  • Form submissions and AJAX requests.
  • The first request after the cache is cleared.

These are often the pages that matter most for sales and for your own productivity. PHP 7 speeds them up directly.

Lower memory use

Each PHP process uses less memory, so a server can run more of them at once. On shared hosting that can mean fewer “memory exhausted” errors. On your own server it can mean handling more traffic before you need to upgrade hardware.

Better time to first byte

Time to first byte, the delay before the browser receives the first part of the page, depends heavily on how long PHP takes to build it. Faster PHP improves this measure, which feeds into everything else on the page.

What it will not fix

PHP 7 makes code run faster. It does not fix:

  • Slow database queries, such as unindexed tables or plugins that run heavy queries on every page.
  • Large images and too many scripts on the front end.
  • Slow external API calls made while the page loads.
  • An overloaded server shared with hundreds of other sites.

It is one part of a wider speed plan. Our WordPress speed optimisation guide covers the rest.

What can break

PHP 7 removed several features that had been deprecated for years. Most modern, well maintained code is fine, but older plugins and themes may not be.

Removed extensions and functions

  • The original mysql_* functions are gone. Code must use mysqli or PDO. WordPress core has supported mysqli since version 3.9, but some old plugins still call mysql_query() directly.
  • ereg functions are gone. Old code using ereg() or split() needs to move to preg_* functions.
  • Old style constructors (a method with the same name as the class) now trigger deprecation notices and will be removed in a future version.

Changes in behaviour

  • Fatal errors are now often thrown as exceptions, which changes how some error handling behaves.
  • Variable handling rules were made more consistent, which changes the result of a few unusual expressions.
  • Some invalid code that used to work quietly now produces errors.

Extensions not yet available

A few PHP extensions took time to be updated for PHP 7. If your site depends on an unusual extension, check it is available on your host’s PHP 7 build.

How to check compatibility

Check WordPress core

WordPress 4.4 and later are compatible with PHP 7. If you are on an older version, update WordPress first.

Check plugins and themes

  • Look at each plugin’s support forum and changelog for mentions of PHP 7.
  • Run a static scan with the PHPCompatibility rules for PHP_CodeSniffer, which flag code that uses removed features.
  • Remove plugins you no longer use. Fewer plugins means fewer things to check.

Test on a staging copy

Static scans miss things. The only reliable test is running the site on PHP 7:

  1. Create a staging copy of the site on a server running PHP 7.
  2. Turn on debugging (WP_DEBUG and logging) so errors are written to a log.
  3. Click through every template and key feature: forms, checkout, search, the admin and any custom functionality.
  4. Read the error log and fix or replace anything that fails.

How to upgrade

On shared or managed hosting

Many hosts now offer a PHP version selector in the control panel. Some only offer PHP 7 on newer plans or servers. If yours does not support it yet, ask when it will, or consider whether it is time to switch. Our guide on how to move WordPress to a new host covers the process.

On your own server

Install PHP 7 alongside your current version where possible, switch one site over, test, then move the rest. Remember to install the extensions your sites need and to enable OPcache.

Have a rollback plan

Whatever the setup, know how to switch back to the previous version quickly if something breaks in production.

If you cannot upgrade yet

Some sites depend on a plugin that will not run on PHP 7. In that case:

  • Move to PHP 5.6 at least. It is faster than older 5.x versions and still supported.
  • Get away from PHP 5.4 and 5.5 as soon as possible. PHP 5.4 no longer receives security fixes, and 5.5 stops receiving them in July 2016.
  • Plan to replace the incompatible plugin, either with an alternative or custom code.

FAQ

Will PHP 7 make my cached pages faster?

Not much. Cached pages are served without running PHP, or with very little. The gains show on uncached pages and in the admin.

Is PHP 7 stable enough for production?

Yes. PHP 7.0 is a stable release and many large sites already run on it. The main risk is your own plugins and code, which is why testing matters.

What about HHVM?

HHVM, Facebook’s alternative PHP engine, also offers big speed gains, and some hosts adopted it. PHP 7 closes much of the gap while staying fully compatible with standard PHP, so most sites are better served by PHP 7.

A faster site from the same server

Upgrading PHP is one of the few speed improvements that costs nothing beyond testing time. We check compatibility, fix what breaks and move sites to newer PHP versions safely. See how we help businesses turn visitors into customers with faster, safer sites.

About the author

Imran M

Leave a Reply

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

Ready to improve your website?

Let's build a faster, higher performing website.