frankenphp
frankenphp copied to clipboard
POC: Enable extensions + staged build
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.
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
Super smart trick!
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 in the /_profiler/phpinfo
it was active for me. Maybe I forget something in the php.ini maybe you can check that.
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.
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?
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
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).
I've added a sed
to the final image to support running one-off commands better.
@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.
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
).
Thank you @withinboredom! Great work
🎉 @withinboredom great work 👍