Hi Dustin and thanks for this bug report. Benchmarking is difficult and repeating one single operation several time is often not a good performance indicator, however I agree we shouldn't see such a huge difference. I can reproduce it too as follows:
1. Launch a Focal LXD container
2. apt install php
3. Run `php test.php` (your test script, unmodified). On my machine this it runs in about 1.5s.
Now in docker:
4. mkdir php-perf-test, copy test.php in this directory and create a Dockerfile containing the following:
5. Run: `docker build -t my-php-app .`
6. Run: `docker run -it --rm --name my-running-app my-php-app`. The test script runs in about 0.25 in this case, on the same machine.
Hi Dustin and thanks for this bug report. Benchmarking is difficult and repeating one single operation several time is often not a good performance indicator, however I agree we shouldn't see such a huge difference. I can reproduce it too as follows:
1. Launch a Focal LXD container
2. apt install php
3. Run `php test.php` (your test script, unmodified). On my machine this it runs in about 1.5s.
Now in docker:
4. mkdir php-perf-test, copy test.php in this directory and create a Dockerfile containing the following:
FROM php:7.4-cli
COPY . /tmp/php
WORKDIR /tmp/php
CMD [ "php", "./test.php" ]
5. Run: `docker build -t my-php-app .`
6. Run: `docker run -it --rm --name my-running-app my-php-app`. The test script runs in about 0.25 in this case, on the same machine.
Version info for the Ubuntu packaged PHP:
$ apt policy php7.4
php7.4:
Installed: 7.4.3-4ubuntu2.2
$ php --version
PHP 7.4.3 (cli) (built: May 26 2020 12:24:22) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies
while the Docker version is:
$ docker run -it --rm --name my-running-app my-php-app php --version
PHP 7.4.6 (cli) (built: May 15 2020 12:47:30) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
This is worth some more investigation.