When you run PHP Vitals benchmarks, you’re running benchmarking tests to know how your web hosting is helping or hindering your WordPress site’s speed. PHP Vitals benchmarks ignore your website’s impact on performance. It instead runs PHP-driven tests directly on the server hosting your website.
But we’re often asked “what exactly is PHP Vitals testing?”.
Understandably, not everyone wants to trawl through our Git repo to see the code and technical descriptions for all 29 tests that make up a PHP Vitals benchmark.
So instead, here’s a comprehensive breakdown of the tests PHP Vitals runs, and a brief explanation of what each test assesses. With 29 different tests measuring your server’s performance, it helps to group the tests into categories.
PHP features
Our first seven tests measure how long it takes your server to run basic PHP-specific code executions. Because WordPress and its websites are powered by PHP, it must run thousands of individual functions to build a web page. The faster your site runs basic PHP functions, the quicker your WordPress site will generate pages for users.
For example, there’s a test measuring the overhead of instantiating, throwing, and catching a basic PHP exception. Then we test how performance is impacted when you execute an anonymous function (one that’s defined without a name) that enforces string and integer type hints.
Other PHP-specific code execution tests we run include:
- Looping through a basic class to measure the speed of directly setting public property values.
- Evaluating the performance impact of accessing private data through
getandsetmethods. - Testing the overhead of using automated
__getand__setmagic methods, compared to direct property access. - Benchmarking the efficiency of a
??operator when checking for existing keys against default values in an array. - Measure the speed of the
<=>operator, combined comparison operator during integer evaluations.
Math
While WordPress isn’t doing complex calculus or 3D physics simulations, PHP constantly runs calculations under-the-hood to run common tasks like counting page numbers and shopping cart totals. If your server has a weak CPU, the impact of these small calculations adds up and can be the bottleneck slowing down your entire WordPress site.
So we put your server’s equation-solving abilities to the test by executing a high-frequency loop of simple arithmetic. This involves lots of straightforward and simple math like addition, subtraction, multiplication, and division.
After that, we get your server to calculate a series of advanced mathematical functions, like sine, cosine, exponents and square roots. We then specifically test the server’s speed at performing simple pre-increment operations (++$a), as well as decrementing operations (--$a).
Strings
WordPress posts and pages are quite literally made up of lots and lots of text. In web development, sequences of text or other characters used as data are known as strings.
PHP works by allocating memory every time a string is created or altered. String efficiency is hugely relevant to WordPress, because WordPress is a CMS designed to display lots and lots of words after all. Every page load involves taking info from databases and putting thousands of strings together to build the final result sent to the browser. The faster a server’s CPU processes these strings, the quicker they’re cleared from the server’s memory, and the faster your WordPress site will load.
Our tests measure how quickly your host’s server performs a series of common string functions. This includes combining multiple strings together and replacing strings using array-based mapping (we’ll talk more about arrays shortly). We also test its performance with more complex string pattern matching, searching for string matches within large blocks of text, benchmark the speed it takes to locate the first occurrence of a substring in a string, and how long it takes to split a long string into an array of strings.
Arrays
Arrays are sets of values, where each entry in the array has a prescribed value . With PHP, you can have arrays of any data types. For example you can have an array of strings, like below:
array(
"wordpress" => "cms",
"php" => "language",
);
Every time a page loads, WordPress performs heavy array operations behind the scenes. If a server’s CPU or memory is slow at processing arrays, WordPress will likely go slowly too.
So we get our tests to run a set of common array functions on your host’s server. This includes measuring the resource impact of a foreach loop iterating through a 1,000-item array. We then test the standard sort() function’s ability to reorder a large numerical array. In the same vein, test the heavier usort() function which sorts numbers by their string length.
We also measure the overhead of creating a large element array using array_fill(), calculate the cost of using the unset() function to remove all keys from an indexed array, and test how long it takes to copy an array via assignment.
Serialization
Serialization converts complex data structures into text formats like JSON, making data more loggable in a database or saved to a file. Because WordPress relies heavily on serialize() and unserialize() functions to save complex settings and plugin data, it has a particularly big performance bottleneck.
That makes it particularly important for us to test. So we measure the impacts of some of the most common serialization functions, like serializing a large array with serialize(), and using json_encode() and json_decode() functions on a nested array.
Crypto, hashing and encryption
Because PHP processes each request on a single CPU thread, heavy hashing and encryption math can’t be shared across multiple cores. These functions are the most resource intensive of everything we test. With the latest versions of PHP they’ve become more efficient, but will still use a lot of CPU. If your server has a slow clock speed, then running complex plugins will directly bottleneck your CPU, dragging down WordPress response times.
So our tests measure how long it takes to compute a couple of different cryptographic hash functions, like the MD5 hash and SHA-256 hash of a text string. We also create a bcrypt password and test how long it takes your server to verify it.
File read/write
Websites can only load as quickly as the hardware inside the server permits. If your server runs on modern NVMe SSDs, latency will be reduced and the server will be able to respond to user requests on your WordPress site much faster. The opposite is true if it’s running on a decade old HDD.
So we test how fast PHP can read and write files on the server. One test writes a small 8KB file to a disk-backed temp stream and reuses the same stream handle across operations. Another test opens a memory-backed stream, writes a payload, reads it back and closes each operation.
You, or your host?
PHP Vitals tests are all about measuring your server’s ability to run PHP functions.
Some of the tests can help you improve your performance by adjusting your php.ini values, and therefore getting PHP working more efficiently. But some are directly related to your web host’s hardware limitations (CPU, memory and file storage are the bottlenecks).
If your PHP Vitals Benchmark scores surprise you, just be aware that the hardware that a host offers you can be misleading. Two different hosts with two different servers can claim to provide 4-core CPUs, but the actual power of those 4 cores and the amount of people sharing them can vary wildly.
That’s why we encourage you to install the PHP Vital plugin, run your PHP Vitals tests, benchmark, and compare.