Understanding PHP Performance with PHP Vitals

performance benchmarks tutorial

PHP Vitals is a comprehensive benchmarking tool that helps you understand and optimize your PHP environment's performance. Let's explore how it works and how to interpret its results.

Quick Start

  1. Install and activate PHP Vitals from the WordPress Plugin Directory
  2. Open PHP Vitals in your WordPress admin and run a benchmark
  3. Choose whether to share your result to the leaderboard

What Gets Tested?

Every benchmark runs the same 29 tests, one after another, directly on your server. They are grouped into seven categories:

Category Tests What they measure
PHP features 7 Exceptions, type hints, object properties, getters and setters, magic methods, null coalescing, the spaceship operator
Maths 4 Simple and complex calculations, incrementing and decrementing
Strings 5 Concatenation, str_replace, regular expressions, strpos, explode
Arrays 6 Looping, sorting, custom sorting with usort, filling, unsetting and copying arrays
Hashing and passwords 3 MD5 and SHA-256 hashes, creating and verifying a bcrypt password hash
Files 2 File stream and memory stream operations
Serialisation 2 PHP serialize and JSON encoding

For a plain-language explanation of each test, see What PHP Vitals is actually testing.

Understanding Results

Your Grade

Every benchmark records a total time: the number of seconds your server takes to run all 29 tests. Lower is better. Your grade comes from comparing that total time with every other server in the PHP Vitals dataset.

There are no fixed time limits for each grade. The grades are worked out like this:

  1. Each server counts once, using its fastest total time.
  2. All servers are ranked from fastest to slowest and split into 12 equal-sized groups, one per grade.
  3. Each grade gets a reference time: the average total time of the servers in its group.
  4. Your result gets the first grade whose reference time is the same as or slower than your total time. Anything slower than the F reference time is also an F.

Current average total time for each grade:

Grade Average time
A+ 5.12s
A 7.53s
A- 9.18s
B+ 10.70s
B 12.08s
B- 13.13s
C+ 14.37s
C 16.09s
C- 18.89s
D 22.81s
E 29.14s
F 53.96s

These times update as new benchmarks come in, so a server that never changes can slip a grade as faster hosts join.

Time and Op/ms per Test

Alongside your total time, the results table shows two figures for each of the 29 tests:

  • Time: how many seconds the test took to run. Lower is better.
  • Op/ms: operations per millisecond, the number of times the test's code ran in each millisecond. Higher is better.

These per-test figures show where your server is fast or slow. For example, a server that scores well on maths but poorly on files may have a fast CPU and slow storage.

Improving Your Result

Your PHP configuration affects your score as well as your hardware. After a benchmark, PHP Vitals can build a prompt containing your results and server configuration. You can copy it into an AI assistant to get optimisation ideas for your setup.

A few common settings are worth checking with your host:

  1. Enable OPcache

OPcache keeps compiled PHP code in memory, so PHP does not recompile it on every request.

opcache.enable=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=16
opcache.max_accelerated_files=10000

Leave opcache.validate_timestamps on (1) for WordPress. If it is off, PHP keeps running the old cached code after a plugin, theme or core update until PHP restarts.

  1. Check memory settings
memory_limit = 256M
realpath_cache_size = 4096K
realpath_cache_ttl = 600
  1. Consider JIT (PHP 8.0 and later)
opcache.jit=tracing
opcache.jit_buffer_size=64M

JIT can speed up CPU-heavy code, such as some of the maths tests, but it usually makes little difference to typical WordPress page loads. Run a benchmark before and after to see what it does on your server.

  1. Use a current PHP version

Newer PHP versions are often faster. See the Insights page for how each PHP version performs across the PHP Vitals dataset.

Comparing Results

Sharing results to the PHP Vitals leaderboard lets you compare your host with other servers around the world, filtered by hosting type, price and location.

Sharing is your choice. Every run is saved in your own WordPress database, and nothing is sent to phpvitals.com unless you turn on leaderboard sharing.

Shared results identify your hosting provider and server location, but not you.

Troubleshooting

If you encounter issues:

  1. A test times out or fails

    • Each test runs in its own request, so check max_execution_time is high enough for one test to finish
  2. Memory Errors

    • Increase memory_limit
    • Monitor memory usage
  3. Extension Errors

    • Verify required extensions
    • Check extension compatibility

Next Steps

  1. Run the benchmark on your server
  2. Compare results with our baseline
  3. Implement recommended optimizations
  4. Re-run tests to verify improvements

Remember, performance optimization is an ongoing process. Regular benchmarking helps maintain optimal performance as your application evolves.