frankenphp icon indicating copy to clipboard operation
frankenphp copied to clipboard

POC: Enable extensions + staged build

Open withinboredom opened this issue 2 years ago • 9 comments

The first stage builds PHP, taking into account some "best practices" from the official image and is built on the official image. It is a stand-in for the official image that is yet to exist (PHP 8.3).

The second stage uses the first stage and copies in the golang build environment from the official golang image. It then builds frankenphp.

The final stage combines the output from the first and second stages from the official PHP image. Once PHP 8.3 is released, this step will just be copying the output from the second stage instead of combining first & second stage.

withinboredom avatar Oct 17 '22 11:10 withinboredom

This is the docker image which is currently working for me using:

FROM php:8.2.0RC4-zts-bullseye AS php-base

ENV PHP_URL="https://github.com/dunglas/php-src/archive/refs/heads/frankenphp-8.2.tar.gz"
ENV PHP_ASC_URL=""
ENV PHP_SHA256=""

# ...

https://github.com/alexander-schranz/frankenphp/blob/feature/php-extensions/Dockerfile

alexander-schranz avatar Oct 17 '22 23:10 alexander-schranz

Super smart trick!

dunglas avatar Oct 18 '22 06:10 dunglas

This is the docker image which is currently working for me using:

FROM php:8.2.0RC4-zts-bullseye AS php-base

ENV PHP_URL="https://github.com/dunglas/php-src/archive/refs/heads/frankenphp-8.2.tar.gz"
ENV PHP_ASC_URL=""
ENV PHP_SHA256=""

# ...

https://github.com/alexander-schranz/frankenphp/blob/feature/php-extensions/Dockerfile

@alexander-schranz I tested your Dockerfile and at first everything looks good to me, but is it possible that opcache has no impact? Although it is active.

stefanpoensgen avatar Oct 18 '22 08:10 stefanpoensgen

@stefanpoensgen in the /_profiler/phpinfo it was active for me. Maybe I forget something in the php.ini maybe you can check that.

alexander-schranz avatar Oct 18 '22 08:10 alexander-schranz

It is active indeed. But if I look at "Symfony initialization" and "Peak memory usage" in the profiler, it is 4 times higher than with my usual caddy+phpfpm setup. These are pretty much the values I get when I disable opcache :D So my first thought was that opcache maybe has no impact at all.

stefanpoensgen avatar Oct 18 '22 08:10 stefanpoensgen

Maybe @dunglas has a hint here. I could not do a performance test yet. As I only uses none Docker PHP runner in other cases, because Docker is really slow on my machine (mac optimization can not be enabled docker freezes then). So todo a performance test I would need to first compile FrankenPHP locally and not in Docker to test it against e.g. PHP-FPM or Roadrunner. Are you using caddy+phpfpm also in Docker?

alexander-schranz avatar Oct 18 '22 09:10 alexander-schranz

Updated the Dockerfile, now builds extensions just fine. I've included the install-php-extensions script for testing in the final stage. So please test:

docker build -t test .
docker run -p 80:80 -p 443:443 -it --rm --entrypoint bash test
# install-php-extensions redis
# frankenphp run --config /etc/Caddyfile

Then verify the extension is present when going to https://localhost

withinboredom avatar Oct 18 '22 09:10 withinboredom

So my first thought was that opcache maybe has no impact at all.

Opcache needs to be installed/enabled separately with this change. We can enable it again, though sometimes opcache is not desired (for example, when building an image with xdebug enabled).

withinboredom avatar Oct 18 '22 09:10 withinboredom

I've added a sed to the final image to support running one-off commands better.

withinboredom avatar Oct 18 '22 12:10 withinboredom

@stefanpoensgen you are correct the opcache is not working as it seems sadly not use the correct tar.gz. I could not yet found out why there are ENV vars if it is no not possible to modify them via the ENV statement.

alexander-schranz avatar Oct 18 '22 20:10 alexander-schranz

you are correct the opcache is not working as it seems sadly not use the correct tar.gz. I could not yet found out why there are ENV vars if it is no not possible to modify them via the ENV statement.

@alexander-schranz, this comment doesn't seem to be related to this PR, but if you're talking about this comment then it is because that env var is only used during the initial build and is never used again. Further, this wouldn't work because none of the scripts expect a .tar.gz, they expect a tar.xz which is a totally different (and incompatible) compression algorithm (-P vs -z with tar).

withinboredom avatar Oct 18 '22 22:10 withinboredom

Thank you @withinboredom! Great work

dunglas avatar Oct 19 '22 05:10 dunglas

🎉 @withinboredom great work 👍

alexander-schranz avatar Oct 19 '22 08:10 alexander-schranz