Upgrading to PHP 7.3 to improve WordPress TTFB

Upgrading to PHP 7.3 to improve WordPress TTFB

This is the hottest summer in Bangkok I can remember having sweated through. So I’m happy to be spending a Sunday afternoon in my air-conditioned home office working through various issues on my main client site in an effort to improve the dreaded Time-To-First-Byte (TTFB) issue.

Thinking about it logically, WordPress is the issue here. Given the client’s site is on a VPN and ‘unmanaged’ (that means I manage it) I don’t have to content with troubleshooting the stack – although one of the first tasks I need to undertake today is to upgrade PHP to version 7.3

Firstly it’s important to have some benchmarks. Without solid data, it’s impossible to know if anything I’m doing is actually having a positive effect on the desired outcome.

I’ll keep things ‘quick and dirty’ and use Google PageSpeed Insights and GTmetrix as my main tools for benchmarking purposes.

My GTmetrix scores are as follows:

PageSpeed Insights gives me initial scores of 37 for mobile and 74 for desktop, and that’s after having already undertaken the following optimizations:

  • Enable GZip on webserver – I thought I had already done this, but was wrong. The site in question is using h2o which is brill, but the directive COMPRESS=ON only applies to the compression of HTTP headers. On-the-fly compression is not something h2o can handle, so assets must be manually compressed using the -k switch. When the directive file.sendcompressed is used the server will send a .gz file instead of the uncompressed version in the same directory.
    You can test whether server compression is enabled here
  • Replaced WP Super Cache with WP Rocket
    WP Rocket has great reviews so I stuck my hand in my pocket and pulled out a crisp 50 buck note to grab a copy. So far, I’m not disappointed. I reckon this is the best money I’ll spend when it comes to improving response times.
    My testing has shown that the WP Autoptimize plugin is doing a better job of handling CSS and JS assets that WP Rocket – better PageSpeed scores by a few points -YMMV
  • Took a quick look at MySQL performance tuning options
    Using the popular PERL script mysqltuner.pl, here’s the output which I’m focusing on

Updating PHP to 7.3

According to various sources, PHP 7.3 offers significant improvements over my current version

I’m going with this article as to how to upgrade to 7.3

Now I have this:

Checking WordPress – first problem encountered is Function create_function() is deprecated

The info in the Stack Overflow post is spot on – once I edit all the widget code, the errors disappear. Good!

It appears upgrading to PHP 7.3 has worked wonders on my TTFB. Here are my new GTmetrix stats:

More errors:

Looks like I need to perform a dist-upgrade as I’m sure PHP is still not 100% happy. When I run locate php.ini it doesn’t locate my newer /etc/php7.3 file versions.

SOLVED: You need to run sudo updatedb which by default only runs once a day.

Tuning PHP and PHP-FPM

I stuffed up by not taking a copy of my php.ini file BEFORE the upgrade. During the upgrade process, I was asked to take some action and chose a menu option which I thought would retain my existing file settings but this doesn’t appear to have worked 🙁

These are the ones I had to add back in:

In case you don’t know, post_max_size should be greater than upload_max_filesize.

Luckily there’s not much I have customized in php.ini – only settings which affect file upload:

As for the PHP FastCGI Process Manager (PHP-FPM), I found an old blog post which helped me to re-set these settings for my box.

I knew there was some value in blogging!

Jetpack errors

Looks like the Jetpack plugin may not yet be fully compatible with PHP 7.3? At least the version of the plugin I was using, being 6.8.1

After updating the plugin, all good. By the way, I created a groovy little script to display active plugins on a WordPress site.

Caveat: Check your Jetpack settings are the same after updating the plugin. For some reasons Jetpack comments had been switched on after the update which I didn’t want.

TTFB significantly improved

Happy with the result, that’s for sure! Looking at waterfall using Gmetrix, waiting has reduced from 822.1ms to 77ms.

Web server running smoothly

It’s been over three weeks now since I performed the upgrade and the client’s web server is running smoothly.

I did come across an h2o error which I followed up – but these don’t appear to be related to the PHP upgrade. In the process I scored an super github username – gonetitsup (an old warfare term)

The additions I’ve made to error logging output are great and all-in-all I’m super happy with the result, even though there’s more work to be done on the tuning front.

Always leave something to do tomorrow!

Leave a Reply

Be the First to Comment!

Notify of
avatar
wpDiscuz