Skip to content
Benchmark for some popular PHP Dependency Injection Containers.
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
app Add phpcs Jan 9, 2019
bin Add Joomla's DI container to the benchmark Dec 30, 2017
build Fix AWS provisioner Jan 13, 2019
public Clear opcache before executing each test Dec 16, 2018
src Create a separate section for the Setup Jan 13, 2019
var Update results Apr 16, 2019
.dockerignore Fix AWS provisioner Jan 13, 2019
.editorconfig Tried to make Docker benchmarks more reliable Jan 17, 2017
.env.dist Removed CLI mode and make error handling better Jan 16, 2017
.gitattributes Initial commit Dec 26, 2016
.gitignore Fix AWS provisioner Jan 13, 2019
.scrutinizer.yml Improved output Dec 26, 2016
.styleci.yml Small fixes Jan 15, 2017
CODE_OF_CONDUCT.md Create CODE_OF_CONDUCT.md Jul 12, 2017
CONTRIBUTING.md Small fixes Jan 15, 2017
Dockerfile Update PHP image Apr 16, 2019
LICENSE Update year Jan 1, 2019
Makefile Add phpcs Jan 9, 2019
README.md
SUPPORT.md Added SUPPORT file Aug 22, 2017
benchmark.sh Fix AWS provisioner Jan 13, 2019
composer.json Apply Woohoo Labs. coding standards Jan 12, 2019
composer.lock Update dependencies to their latest version Apr 16, 2019
docker-compose.aws.yml Add support for running the tests on AWS EC2 Jan 9, 2019
docker-compose.yml Add support for running the tests on AWS EC2 Jan 9, 2019
phpcs.xml Apply Woohoo Labs. coding standards Jan 12, 2019

README.md

PHP DI Container Benchmarks

Software License Gitter

Table of Contents

Introduction

In 2014, a really interesting benchmark about DI Containers for PHP was published on Sitepoint. Unfortunately, the implementation of the tests turned out to be quite controversial, so the benchmark itself wasn't really insightful.

I have been interested in the topic since then so I wanted to conduct another benchmark that also tries to measure real-life performance, while being as unbiased and reliable as possible.

Results

You can find the benchmark results here.

Install

You can simply download or clone this repository as well as install it via Composer by running the command below:

$ composer require kocsismate/di-container-benchmarks:dev-master

Usage

Usage with Docker

As a prerequisite, Docker Compose and at least Docker 17.06 CE has to be installed on your machine in order to use this benchmark method.

Copy the .env.dist file to .env and feel free to override the values in it. Now, you can run

./benchmark.sh docker

to execute the measurements.

The HTML output will be generated in the "var" directory.

Usage on AWS EC2

As a prerequisite, Terraform and git has to be installed on your machine in order to use this benchmark method.

First, create the necessary config file by copying the aws.tfvars.dist to aws.tfvars in the build/infrastructure/config/aws.tfvars.dist directory:

cp build/infrastructure/config/aws.tfvars.dist build/infrastructure/config/aws.tfvars

Then, override the values in it:

  • ssh_key_name: the name of your key pair added to EC2
  • ssh_private_key: the file name of your private key
  • region: it is "eu-central-1" by default, but you should choose the closest one to your area
  • instance_type: it is "C5.large" by default (this instance type is out of the scope of the free tier!)

Finally, you have to copy your private key in the "build/infrastructure/config" directory with a file name that matches the one defined in the ssh_private_key setting.

Now, you are ready to go:

export AWS_ACCESS_KEY_ID={{ YOUR AWS ACCESS KEY }}
export AWS_SECRET_ACCESS_KEY={{ YOUR AWS SECRET KEY }}
./benchmark.sh aws

The HTML output will be generated in the "var" directory.

Usage on your host machine

If the above possibilities aren't available to you then you have to take several steps before running the benchmark:

  • Install a web server and configure it to be able to serve "public/index.php"
  • Install PHP 7.3 at least with OPcache enabled
  • Install Composer
  • Set the BENCHMARK_URL environment variable to the URL where "public/index.php" is available. For instance:
export BENCHMARK_URL=http://localhost/index.php

Now you can simply type the following in order to run the benchmark:

.\benchmark.sh host

If you don't want to specify the benchmark URL as an environment variable then you can also pass it as a parameter:

./benchmark.sh host http://localhost/index.php

Usage from the browser

You can even run tests manually from your browser. When the benchmark's Docker containers are running, just visit localhost:8090, otherwise you have to locate the BENCHMARK_URL URL (mentioned in the previous section). For further information, refer to the URL in question, it provides you with detailed instructions.

Contributing

Please see CONTRIBUTING for details.

Support

Please see SUPPORT for details.

Credits

License

The MIT License (MIT). Please see the License File for more information.

You can’t perform that action at this time.