I am not an expert at all (for now) when it comes to PHP performance testing.

In the past I did performance optimizations, backtrace checking, profiling with Xdebug, xhprof and tools like Blackfire.

During some of the experiments we are going to do, we might use one, or more of these tools to validate assumptions.

Initially all the tests will be done on my local machine:

Output of screenfetch

rob@MacBook-Pro-van-Rob
OS: 64bit macOS 11.2.3 20D91
Kernel: x86_64 Darwin 20.3.0
Packages: 131
Shell: zsh 5.8
Resolution: 3840x2160
DE: Aqua
WM: Quartz Compositor
WM Theme: Blue
Disk: 423G / 500G (88%)
CPU: Intel Core i9-9880H @ 2.30GHz
GPU: Intel UHD Graphics 630 / Radeon Pro 560X
RAM: 8816MiB / 16384MiB

While it is not ideal to run performance tests on a personal machine because the CPU might be busy doing other tasks it will give a good indication of how well someone is performing if all tests run from the same machine over multiple tries.

If this testing gets more serious, I will consider setting up a dedicated machine to run tests on.

All tests will execute using the command line version to avoid overhead of Apache or Nginx. But it still might be we do some ab testing here and there.

Docker

Tests will run in a configured docker instance.

We will use the default PHP8 image with opcache disabled (extension not loaded).

At some points we might enable it briefly to see how it would affect performance.

The docker instance will be given 2 GB of memory and access to 1 CPU cores. This will ensure that the tests are always running in a fixed environment setup.

It will also allow us to quickly restart a system if we notice it is messed up. And of course we’ll not be messing up the main system which I used every day to earn my bread.

The docker setup and tests will be hosted on GitHub once they are somewhat stable and good to be shared.

At any time if you have suggestions on how to improve accuracy of tests, let me know! Twitter direct messages are open.

The staring files, for the most up to date version check the GitHub repository as they might change.

Dockerfile:

FROM php:8.0-apache

## Enable mod reload
RUN cp $APACHE_CONFDIR/mods-available/rewrite.load $APACHE_CONFDIR/mods-enabled/rewrite.load

Docker compose file:

version: "3.7"
services:
  php:
    build:
      dockerfile: ./docker/php.Dockerfile
      context: .
    restart: always
    volumes:
      - "./:/var/www/html/"
    ports:
      - "8888:80"

How to test the performance?

It’s not that easy to test bare performances. We do not want to use PHP for that because we want to remove any overhead.

Instead we are going to use a rust utility procrec in combination with a boot script to run a number of iterations.

I did modify procrec a bit to use millisecond timings and to allow exporting the plots to a png file.

We will use gnuplot to get some graphs.

In addition to this, we will use a Makefile to store all of the tests so it can be ran easily.

Repository

You can find some initial experiment results on the GitHub page: Results

You can also directly view the GitHub repository.

Some interesting findings already, inline concatenation is the fastest. Objects use far less memory then arrays, and using functions namespaced in namespaced files a faster!