/php-di-container-benchmarks

Benchmark for some popular PHP Dependency Injection Containers

Primary LanguagePHPMIT LicenseMIT

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

First of all, a fresh version of Docker Compose and at least Docker 17.06 CE has to be installed on your machine.

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

./benchmark.sh docker

on Unix-based systems, while Windows users should use

.\benchmark.bat docker

to execute the measurements.

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

Usage without Docker

If using Docker is not an option for 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.2 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

Windows users can use the benchmark.bat instead.

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.