Measuring WordPress speed

Written: 9.12.2017 Updated: 27.1.2020

Improving the performance of WordPress sites is a popular topic among WordPress developers. E-commerce owners know that faster websites mean more conversions and more sales. Everybody hates to wait for pages that take long to load. However, the knowledge of how to correctly improve the performance of WordPress sites is still surprisingly scarce.

The most basic and most central skill is how to measure the current speed of a WordPress site. Developers who don’t know how to measure the speed of their code or site, have a slim chance of making anything faster. Trying our 10 things that might (and mostly might not) improve a site is a waste of time and depends on the luck of striking something that matters.

For WordPress, the most basic measurement is to time how long it takes for PHP to produce the HTML output. The most straightforward way to test any site anywhere is to use the command-line tool curl. Just install the package (e.g. apt install curl in Debian based Linux machines) and run curl while printing the time_total value:

curl -s -o /dev/null -w "%{time_total}\n" https://example.com/
0.123

This means that the site took 123 milliseconds to load from the server to the machine running curl. To avoid the network lag between the server and your own computer, simply log into the server using ssh and run the curl to cut out all network hops in the middle.

If the WordPress site is running in a professional server environment, there will be some caching layers between the site and the world outside. This caching layer will deliver the HTML content much faster than PHP would. To make sure you always get the response all the way from PHP, you need to burst the cache layer using the No-Pragma header (this is the same header your browser emits when you press Ctrl+F5).

curl -s -o /dev/null -w "%{time_total}\n" -H "Pragma: no-cache" https://example.com/

Some times the PHP execution will not be identical on every page load, or the server environment might be noisy. To make multiple measurements and get the average response time, you can use some for and awk scripting:

export LC_NUMERIC=C
for i in {1..20}
do 
 curl -so /dev/null -w "%{time_total}\n" https://example.com/
done | awk '{ sum += $1; n++; print $1 } END { if (n > 0) print "AVG: " sum / n; }'

0.209
0.107
0.152
AVG: 0.1378

Finally, if you have SSH access to the server and wp-cli is installed, you can disable one plugin at a time with this handy bash script snippet to see if there is a single plugin that drastically affects the PHP page load time:

for p in $(wp plugin list --fields=name --status=active)
do
  echo $p
  wp plugin deactivate --skip-plugins $p
  for i in {1..5}
  do
    curl -so /dev/null -w "%{time_total}\n" \
    -H "Pragma: no-cache" https://example.com/
  done
  wp plugin activate $p 
done

We like to preach about WordPress performance. Making websites faster does not only make the world run more smoothly, but it actually also saves computer processing power and electricity, and thus helps to save the world!

Below are the slides from WordCamp Athens where you can find more information about the topic.

3 comments on “Measuring WordPress speed”

Leave a comment

Otto Kekäläinen

CEO

Search Seravo.com

Categories

More reading

MariaDB Relies on Seravo

10.1.2020

MariaDB is one of the most popular open-source databases. It is managed by the MariaDB Foundation. How the original developers […]

5 Key Reasons Why Your WordPress Site is Slow

17.12.2019

If your site fails to load fast, your business is most certainly losing money. Did you know that a slow […]

PHP 7.4 released

3.12.2019

The PHP project announced the release of PHP 7.4 on November 28th, 2019. As usual, they have also published a […]