Configuration

Customizing the image

Tune PHP, OPcache, and the web server with environment variables, or add your own php.ini.

BenchKit is built on the serversideup/php images, and inherits their environment variables. You can change how PHP is configured and run again without rebuilding anything, which is what makes BenchKit useful for learning rather than only for measuring.

Common settings to change

docker-compose.yml
services:
  benchkit:
    image: serversideup/benchkit-laravel:latest
    ports:
      - "80:8080"
    environment:
      # OPcache, which BenchKit turns on by default
      PHP_OPCACHE_ENABLE: "1"
      PHP_OPCACHE_JIT: "tracing"
      PHP_OPCACHE_MEMORY_CONSUMPTION: "256"
      # PHP itself
      PHP_MEMORY_LIMIT: "512M"
      # The FPM pool, on the fpm-nginx and fpm-apache variations
      PHP_FPM_PM_CONTROL: "dynamic"
      PHP_FPM_PM_MAX_CHILDREN: "20"
Every variable in the serversideup/php environment variable specification works in BenchKit. The specification is the full list.

Settings without an environment variable

The specification covers most of what you would reach for, but not everything in php.ini has a variable. When you need one that doesn't, add your own .ini file. You can mount it at runtime or bake it into an image.

Nothing to build. Edit the file, restart the container, run again. This is usually what you want, since a BenchKit server is temporary anyway.

zzz-custom-php.ini
; Files in conf.d load alphabetically. The zzz prefix puts this after
; the file serversideup/php writes from your environment variables,
; so anything set here wins where the two overlap.

; realpath_cache_ttl has a variable (PHP_REALPATH_CACHE_TTL).
; realpath_cache_size does not, so it belongs here.
; Both values below are raised from the PHP defaults of 4096K and 5.
realpath_cache_size = 16384K

opcache.max_wasted_percentage = 10
The serversideup/php guide to changing PHP settings covers this in more depth, including how to replace the default configuration outright rather than layer on top of it.

Turning a setting into an experiment

Because these are environment variables, you can measure what any one of them is worth on your own hardware.

Run with the setting off

Start BenchKit with the setting disabled, for example PHP_OPCACHE_ENABLE=0, and run a benchmark.

Run with the setting on

Restart with the setting enabled and run the same benchmark again.

Compare the two runs

Open both runs in Compare. The environment panel shows the php.ini values that were in effect for each one, which tells you exactly which change produced the difference.

OPcache is the setting that changes the numbers most. With it disabled, PHP recompiles your source on every request, and every other measurement on the page is describing that instead of the thing you meant to test. BenchKit warns you before a run starts if it detects OPcache is off.

Choosing the web server

Which web server runs is decided by the image variation you pull, not by an environment variable. See Image variations.