From 7012d5c82de1de93cd2119d63478839fd539c79c Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Wed, 4 Nov 2026 11:22:57 +0100 Subject: [PATCH 1/3] One binary for php and php-fpm on PHP 8.5 (--enable-cli-fpm) Backport of php/php-src#23558, applied when src/cli-fpm has a patch for the PHP version: php-fpm is a symlink to php, so FPM maps the binary the CLI bootstrap already loaded (-12 to -16 ms of FPM cold start, 8 MB less memory). --- Dockerfile | 15 ++- src/cli-fpm/php-85.patch | 255 +++++++++++++++++++++++++++++++++++++++ tests/Makefile | 3 + 3 files changed, 271 insertions(+), 2 deletions(-) create mode 100644 src/cli-fpm/php-85.patch diff --git a/Dockerfile b/Dockerfile index 63473ac2..dd10e5f3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -94,6 +94,14 @@ WORKDIR /tmp/php RUN curl --location --silent --show-error --fail --retry 3 "https://www.php.net/distributions/php-${VERSION_PHP}.tar.gz" \ | tar xzC . --strip-components=1 +# One binary for php and php-fpm: `php` runs FPM when invoked as `php-fpm` (--enable-cli-fpm, +# https://github.com/php/php-src/pull/23558, not in PHP yet). FPM then maps the file that the CLI +# (Bref's bootstrap) already loaded: -12 to -16 ms of FPM cold start and 8 MB less memory. +# Applied when src/cli-fpm has a patch for this PHP version. +ARG PHP_VERSION +COPY --link src/cli-fpm /tmp/cli-fpm +RUN if [ -f "/tmp/cli-fpm/php-${PHP_VERSION}.patch" ]; then patch -p1 < "/tmp/cli-fpm/php-${PHP_VERSION}.patch"; fi + # Configure the build # -fstack-protector-strong : Be paranoid about stack overflows # -fpic : Make PHP's main executable position-independent (improves ASLR security mechanism, and has no performance impact on x86_64) @@ -118,6 +126,7 @@ RUN CFLAGS="-fstack-protector-strong -fpic -fpie -O2 -ffunction-sections -fdata- --with-config-file-scan-dir=/etc/php/conf.d:/opt/bref/etc/php/conf.d:/var/task/php/conf.d \ --enable-cli \ --enable-fpm \ + $([ -f "/tmp/cli-fpm/php-${PHP_VERSION}.patch" ] && echo --enable-cli-fpm) \ --disable-cgi \ --disable-phpdbg \ --with-openssl \ @@ -149,7 +158,8 @@ RUN make -j "$(nproc)" # Override PEAR's PHAR URL because pear.php.net is down RUN set -xe; \ make install PEAR_INSTALLER_URL='https://github.com/pear/pearweb_phars/raw/master/install-pear-nozlib.phar'; \ - make clean + make clean; \ + if [ -f "/tmp/cli-fpm/php-${PHP_VERSION}.patch" ]; then ln -sf ../bin/php /usr/local/sbin/php-fpm; fi # Optional extensions installed with `pecl`, not enabled by default RUN pecl install APCu @@ -204,7 +214,8 @@ RUN set -xe; \ ln -sf /etc/ssl/certs/ca-certificates.crt /etc/pki/tls/cert.pem COPY --link --from=build-environment /usr/local/bin/php /usr/local/bin/php -COPY --link --from=build-environment /usr/local/sbin/php-fpm /usr/local/sbin/php-fpm +# php-fpm is either a binary or a symlink to php (--enable-cli-fpm): copy the directory to keep symlinks +COPY --link --from=build-environment /usr/local/sbin/ /usr/local/sbin/ COPY --link --from=build-environment /usr/local/lib/php/extensions /usr/local/lib/php/extensions COPY --link src/php.ini /etc/php/conf.d/50-bref.ini diff --git a/src/cli-fpm/php-85.patch b/src/cli-fpm/php-85.patch new file mode 100644 index 00000000..a1881eb0 --- /dev/null +++ b/src/cli-fpm/php-85.patch @@ -0,0 +1,255 @@ +--enable-cli-fpm: link the FPM SAPI into the CLI binary (`php --fpm`, or `php` invoked as `php-fpm`). +Backport to PHP 8.5 of https://github.com/php/php-src/pull/23558 (not merged yet): the FPM part of +the PR as is, the CLI part adapted because 8.5 has no sapi/cli/php_cli_main.c (see +brefphp/sandbox results/2026-10-06-cli-fpm.md). Applies to PHP 8.5.11 and 8.5.12. + +diff --git a/sapi/cli/config.m4 b/sapi/cli/config.m4 +index 76c2d64e..631b2565 100644 +--- a/sapi/cli/config.m4 ++++ b/sapi/cli/config.m4 +@@ -5,6 +5,22 @@ PHP_ARG_ENABLE([cli], + [yes], + [no]) + ++PHP_ARG_ENABLE([cli-fpm], ++ [whether to link FPM into the CLI binary], ++ [AS_HELP_STRING([--enable-cli-fpm], ++ [Link the FPM SAPI into the CLI binary, so that "php --fpm" runs php-fpm ++ (requires --enable-fpm)])], ++ [no], ++ [no]) ++ ++if test "$PHP_CLI_FPM" != "no"; then ++ if test "$PHP_CLI" = "no" || test "$PHP_FPM" = "no"; then ++ AC_MSG_ERROR([--enable-cli-fpm requires both the CLI and the FPM SAPI]) ++ fi ++ AC_DEFINE([PHP_CLI_WITH_FPM], [1], ++ [Define to 1 if the FPM SAPI is linked into the CLI binary.]) ++fi ++ + if test "$PHP_CLI" != "no"; then + AC_CHECK_FUNCS([setproctitle]) + +@@ -34,6 +50,8 @@ if test "$PHP_CLI" != "no"; then + [program], + [php_cli.c php_http_parser.c php_cli_server.c ps_title.c php_cli_process_title.c], + [-DZEND_ENABLE_STATIC_TSRMLS_CACHE=1]) ++ AS_VAR_IF([PHP_CLI_FPM], [no],, ++ [PHP_CLI_OBJS="$PHP_CLI_OBJS \$(PHP_FASTCGI_OBJS) \$(PHP_FPM_SHARED_OBJS)"]) + + AS_CASE([$host_alias], + [*aix*], [ +diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c +index 92368696..c8d74d20 100644 +--- a/sapi/cli/php_cli.c ++++ b/sapi/cli/php_cli.c +@@ -500,6 +500,9 @@ static void php_cli_usage(char *argv0) + "\n" + " --ini Show configuration file names\n" + " --ini=diff Show INI entries that differ from the built-in default\n" ++#ifdef PHP_CLI_WITH_FPM ++ " --fpm Run as php-fpm, passing the remaining arguments to it\n" ++#endif + "\n" + " --rf Show information about function .\n" + " --rc Show information about class .\n" +@@ -1193,9 +1196,37 @@ static int do_cli(int argc, char **argv) /* {{{ */ + } + /* }}} */ + ++#ifdef PHP_CLI_WITH_FPM ++/* Backport to PHP 8.5 of php/php-src#23558, whose php_cli_main.c does not exist ++ * here: the former main() becomes do_php_cli() */ ++#include "sapi/fpm/fpm/fpm.h" ++ ++static int do_php_cli(int argc, char *argv[]); ++ ++int main(int argc, char *argv[]) ++{ ++ /* Running as "php-fpm*" (e.g. a php-fpm symlink to php) or as ++ * "php --fpm [args]" runs the FPM SAPI. argv is passed as is because FPM ++ * re-executes it on reload; FPM options start after "--fpm". */ ++ if (argc > 0 && argv[0]) { ++ const char *name = strrchr(argv[0], '/'); ++ name = name ? name + 1 : argv[0]; ++ if (strncmp(name, "php-fpm", strlen("php-fpm")) == 0) { ++ return fpm_main(argc, argv, 1); ++ } ++ } ++ if (argc > 1 && strcmp(argv[1], "--fpm") == 0) { ++ return fpm_main(argc, argv, 2); ++ } ++ return do_php_cli(argc, argv); ++} ++#endif ++ + /* {{{ main */ + #ifdef PHP_CLI_WIN32_NO_CONSOLE + int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) ++#elif defined(PHP_CLI_WITH_FPM) ++static int do_php_cli(int argc, char *argv[]) + #else + int main(int argc, char *argv[]) + #endif +diff --git a/sapi/fpm/config.m4 b/sapi/fpm/config.m4 +index 4d4952ee..d4a8ccbb 100644 +--- a/sapi/fpm/config.m4 ++++ b/sapi/fpm/config.m4 +@@ -1,10 +1,3 @@ +-PHP_ARG_ENABLE([fpm], +- [for FPM build], +- [AS_HELP_STRING([--enable-fpm], +- [Enable building of the fpm SAPI executable])], +- [no], +- [no]) +- + dnl Configure checks. + AC_DEFUN([PHP_FPM_CLOCK], [ + AC_CHECK_FUNCS([clock_gettime],, [ +@@ -557,9 +550,18 @@ if test "$PHP_FPM" != "no"; then + + PHP_SELECT_SAPI([fpm], + [program], +- [$PHP_FPM_FILES $PHP_FPM_TRACE_FILES $PHP_FPM_SD_FILES], ++ [php_fpm_main.c], + [-I$abs_srcdir/sapi/fpm -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1]) + ++ dnl Everything except the main() entry point, so that the CLI binary can link ++ dnl the same objects for fpm_main() (--enable-cli-fpm). ++ PHP_ADD_SOURCES_X([sapi/fpm], ++ [$PHP_FPM_FILES $PHP_FPM_TRACE_FILES $PHP_FPM_SD_FILES], ++ [-I$abs_srcdir/sapi/fpm -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1], ++ [PHP_FPM_SHARED_OBJS]) ++ PHP_FPM_OBJS="$PHP_FPM_OBJS $PHP_FPM_SHARED_OBJS" ++ PHP_SUBST([PHP_FPM_SHARED_OBJS]) ++ + AS_CASE([$host_alias], + [*aix*], [ + BUILD_FPM="echo '\#! .' > php.sym && echo >>php.sym && nm -BCpg \`echo \$(PHP_GLOBAL_OBJS) \$(PHP_BINARY_OBJS) \$(PHP_FPM_OBJS) | sed 's/\([A-Za-z0-9_]*\)\.lo/\1.o/g'\` | \$(AWK) '{ if (((\$\$2 == \"T\") || (\$\$2 == \"D\") || (\$\$2 == \"B\")) && (substr(\$\$3,1,1) != \".\")) { print \$\$3 } }' | sort -u >> php.sym && \$(LIBTOOL) --tag=CC --mode=link \$(CC) -export-dynamic \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS_PROGRAM) \$(LDFLAGS) -Wl,-brtl -Wl,-bE:php.sym \$(PHP_RPATHS) \$(PHP_GLOBAL_OBJS) \$(PHP_BINARY_OBJS) \$(PHP_FASTCGI_OBJS) \$(PHP_FPM_OBJS) \$(EXTRA_LIBS) \$(FPM_EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_FPM_PATH)" +@@ -573,4 +575,5 @@ if test "$PHP_FPM" != "no"; then + PHP_SUBST([SAPI_FPM_PATH]) + PHP_SUBST([BUILD_FPM]) + PHP_SUBST([FPM_EXTRA_LIBS]) ++ AS_VAR_IF([PHP_CLI_FPM], [no],, [EXTRA_LIBS="$EXTRA_LIBS $FPM_EXTRA_LIBS"]) + fi +diff --git a/sapi/fpm/config0.m4 b/sapi/fpm/config0.m4 +new file mode 100644 +index 00000000..d00da52b +--- /dev/null ++++ b/sapi/fpm/config0.m4 +@@ -0,0 +1,6 @@ ++PHP_ARG_ENABLE([fpm], ++ [for FPM build], ++ [AS_HELP_STRING([--enable-fpm], ++ [Enable building of the fpm SAPI executable])], ++ [no], ++ [no]) +diff --git a/sapi/fpm/fpm/fpm.h b/sapi/fpm/fpm/fpm.h +index ec036a2d..a018948c 100644 +--- a/sapi/fpm/fpm/fpm.h ++++ b/sapi/fpm/fpm/fpm.h +@@ -41,6 +41,10 @@ enum fpm_init_return_status { + }; + + int fpm_run(int *max_requests); ++/* this performs full fpm-SAPI boot: the former main() of php-fpm. ++ * argv must be the process' original argv (it is re-executed on reload), ++ * FPM options are parsed starting at argv[first_arg]. */ ++int fpm_main(int argc, char *argv[], int first_arg); + enum fpm_init_return_status fpm_init(int argc, char **argv, char *config, char *prefix, char *pid, int test_conf, int run_as_root, int force_daemon, int force_stderr); + + struct fpm_globals_s { +diff --git a/sapi/fpm/fpm/fpm_main.c b/sapi/fpm/fpm/fpm_main.c +index cc89b8c0..75b159c0 100644 +--- a/sapi/fpm/fpm/fpm_main.c ++++ b/sapi/fpm/fpm/fpm_main.c +@@ -1513,7 +1513,7 @@ PHP_FUNCTION(fastcgi_finish_request) /* {{{ */ + } + /* }}} */ + +-PHP_FUNCTION(apache_request_headers) /* {{{ */ ++PHP_FUNCTION(fpm_request_headers) /* {{{ */ + { + fcgi_request *request; + +@@ -1553,8 +1553,8 @@ static zend_module_entry cgi_module_entry = { + STANDARD_MODULE_PROPERTIES + }; + +-/* {{{ main */ +-int main(int argc, char *argv[]) ++/* {{{ fpm_main */ ++int fpm_main(int argc, char *argv[], int first_arg) + { + int exit_status = FPM_EXIT_OK; + int c, use_extended_info = 0; +@@ -1615,6 +1615,7 @@ int main(int argc, char *argv[]) + + php_ini_builder_init(&ini_builder); + ++ php_optind = first_arg; + while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) { + switch (c) { + case 'c': +diff --git a/sapi/fpm/fpm/fpm_main.stub.php b/sapi/fpm/fpm/fpm_main.stub.php +index 70cd2752..8cd91dc9 100644 +--- a/sapi/fpm/fpm/fpm_main.stub.php ++++ b/sapi/fpm/fpm/fpm_main.stub.php +@@ -4,9 +4,10 @@ + + function fastcgi_finish_request(): bool {} + ++/** @implementation-alias fpm_request_headers */ + function apache_request_headers(): array {} + +-/** @alias apache_request_headers */ ++/** @implementation-alias fpm_request_headers */ + function getallheaders(): array {} + + function fpm_get_status(): array|false {} +diff --git a/sapi/fpm/fpm/fpm_main_arginfo.h b/sapi/fpm/fpm/fpm_main_arginfo.h +index 2d6ae3cc..fe3ba73d 100644 +--- a/sapi/fpm/fpm/fpm_main_arginfo.h ++++ b/sapi/fpm/fpm/fpm_main_arginfo.h +@@ -13,13 +13,13 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_fpm_get_status, 0, 0, MAY_BE_ARR + ZEND_END_ARG_INFO() + + ZEND_FUNCTION(fastcgi_finish_request); +-ZEND_FUNCTION(apache_request_headers); ++ZEND_FUNCTION(fpm_request_headers); + ZEND_FUNCTION(fpm_get_status); + + static const zend_function_entry ext_functions[] = { + ZEND_FE(fastcgi_finish_request, arginfo_fastcgi_finish_request) +- ZEND_FE(apache_request_headers, arginfo_apache_request_headers) +- ZEND_RAW_FENTRY("getallheaders", zif_apache_request_headers, arginfo_getallheaders, 0, NULL, NULL) ++ ZEND_RAW_FENTRY("apache_request_headers", zif_fpm_request_headers, arginfo_apache_request_headers, 0, NULL, NULL) ++ ZEND_RAW_FENTRY("getallheaders", zif_fpm_request_headers, arginfo_getallheaders, 0, NULL, NULL) + ZEND_FE(fpm_get_status, arginfo_fpm_get_status) + ZEND_FE_END + }; +diff --git a/sapi/fpm/php_fpm_main.c b/sapi/fpm/php_fpm_main.c +new file mode 100644 +index 00000000..ab06cb43 +--- /dev/null ++++ b/sapi/fpm/php_fpm_main.c +@@ -0,0 +1,19 @@ ++/* ++ +----------------------------------------------------------------------+ ++ | Copyright © The PHP Group and Contributors. | ++ +----------------------------------------------------------------------+ ++ | This source file is subject to the Modified BSD License that is | ++ | bundled with this package in the file LICENSE, and is available | ++ | through the World Wide Web at . | ++ | | ++ | SPDX-License-Identifier: BSD-3-Clause | ++ +----------------------------------------------------------------------+ ++*/ ++ ++#include "php.h" ++#include "fpm/fpm.h" ++ ++int main(int argc, char *argv[]) ++{ ++ return fpm_main(argc, argv, 1); ++} diff --git a/tests/Makefile b/tests/Makefile index 68b47e0e..401d9971 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -7,6 +7,9 @@ test-%: vendor # Image layout: Lambda needs /etc/hosts and /var/task, layers would hide /opt docker run --platform=${DOCKER_PLATFORM} --rm --entrypoint=sh bref/php-$* -c \ 'test -f /etc/hosts && test -d /var/task && test -x /var/runtime/bootstrap && test -z "$$(ls -A /opt)" && test "$$(stat -c %a /tmp)" = 1777' + # Since PHP 8.5, php-fpm is the php binary itself (--enable-cli-fpm) + docker run --platform=${DOCKER_PLATFORM} --rm --entrypoint=sh bref/php-$* -c \ + '/usr/local/sbin/php-fpm -v | grep -q fpm-fcgi && { [ $* -lt 85 ] || [ "$$(readlink -f /usr/local/sbin/php-fpm)" = /usr/local/bin/php ]; }' docker run --platform=${DOCKER_PLATFORM} --rm -v=$(PWD):/var/task:ro --entrypoint=php bref/php-$* test_1_binary.php $* docker run --platform=${DOCKER_PLATFORM} --rm -v=$(PWD):/var/task:ro --entrypoint=php bref/php-$*-dev test_1_binary.php $* From 3a3c6067f156e8f77fe12c72834b3eb56902c98c Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Wed, 4 Nov 2026 11:42:13 +0100 Subject: [PATCH 2/3] Support PHP 8.6 (8.6.0RC5) - Pre-releases are downloaded from the php-src tag on GitHub (php.net only has final releases). - One binary for php and php-fpm on 8.6 too: php/php-src#23558's diff, plus the rename of FPM's apache_request_headers() implementation that master has (php/php-src#24249) and PHP-8.6 does not. - APCu, phpredis and xdebug have no release that compiles with 8.6 yet: built from pinned commits of their main branches on 8.6 only. --- .github/workflows/release.yml | 4 +- .github/workflows/tests.yml | 2 +- Dockerfile | 41 ++++- Makefile | 8 +- docker-bake.hcl | 2 + src/cli-fpm/php-86.patch | 314 ++++++++++++++++++++++++++++++++++ tests/Makefile | 2 +- 7 files changed, 360 insertions(+), 13 deletions(-) create mode 100644 src/cli-fpm/php-86.patch diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6d7ae41c..098afade 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,7 +19,7 @@ jobs: strategy: matrix: platform: [ 'linux/amd64', 'linux/arm64' ] - php_version: [ '83', '84', '85' ] + php_version: [ '83', '84', '85', '86' ] steps: - uses: actions/checkout@v6 @@ -46,7 +46,7 @@ jobs: timeout-minutes: 60 strategy: matrix: - php_version: [ '83', '84', '85' ] + php_version: [ '83', '84', '85', '86' ] steps: - uses: actions/checkout@v6 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 620a82fb..698b36cc 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -25,7 +25,7 @@ jobs: script: | const matrix = { platform: ['linux/amd64', 'linux/arm64'], - php_version: ['83', '84', '85'], + php_version: ['83', '84', '85', '86'], } // If this is a third-party pull request, skip ARM builds diff --git a/Dockerfile b/Dockerfile index dd10e5f3..20540052 100644 --- a/Dockerfile +++ b/Dockerfile @@ -91,8 +91,13 @@ RUN set -xe; \ # --fail makes sure that curl returns an error instead of fetching the 404 page ARG VERSION_PHP WORKDIR /tmp/php -RUN curl --location --silent --show-error --fail --retry 3 "https://www.php.net/distributions/php-${VERSION_PHP}.tar.gz" \ - | tar xzC . --strip-components=1 +# Pre-releases (alpha, beta, RC) are not on php.net/distributions: take the tag's source from GitHub +# (without the generated files, which `buildconf` below generates) +RUN case "${VERSION_PHP}" in \ + *alpha*|*beta*|*RC*) url="https://github.com/php/php-src/archive/refs/tags/php-${VERSION_PHP}.tar.gz" ;; \ + *) url="https://www.php.net/distributions/php-${VERSION_PHP}.tar.gz" ;; \ + esac; \ + curl --location --silent --show-error --fail --retry 3 "$url" | tar xzC . --strip-components=1 # One binary for php and php-fpm: `php` runs FPM when invoked as `php-fpm` (--enable-cli-fpm, # https://github.com/php/php-src/pull/23558, not in PHP yet). FPM then maps the file that the CLI @@ -162,8 +167,24 @@ RUN set -xe; \ if [ -f "/tmp/cli-fpm/php-${PHP_VERSION}.patch" ]; then ln -sf ../bin/php /usr/local/sbin/php-fpm; fi # Optional extensions installed with `pecl`, not enabled by default -RUN pecl install APCu -RUN pecl install redis-6.3.0 +# APCu's latest release (5.1.28) does not compile with PHP 8.6: use its main branch (pinned) until 5.1.29 +RUN if [ "${PHP_VERSION}" -ge 86 ]; then \ + mkdir -p /tmp/apcu && cd /tmp/apcu \ + && curl --location --silent --show-error --fail --retry 3 https://github.com/krakjoe/apcu/archive/fb2c942552a3f5dab7f4dea4afb5cf0831222c57.tar.gz \ + | tar xzC . --strip-components=1 \ + && phpize && ./configure && make && make install && cd / && rm -rf /tmp/apcu; \ + else \ + pecl install APCu; \ + fi +# phpredis' latest release (6.3.0) does not compile with PHP 8.6: use its develop branch (pinned) until the next release +RUN if [ "${PHP_VERSION}" -ge 86 ]; then \ + mkdir -p /tmp/redis && cd /tmp/redis \ + && curl --location --silent --show-error --fail --retry 3 https://github.com/phpredis/phpredis/archive/959dee1ca9ed55500cf90365419f8232eca3a99c.tar.gz \ + | tar xzC . --strip-components=1 \ + && phpize && ./configure && make && make install && cd / && rm -rf /tmp/redis; \ + else \ + pecl install redis-6.3.0; \ + fi # Gather all extensions in one directory, independent of PHP's internal API version RUN set -xe; \ @@ -252,7 +273,17 @@ FROM build-environment AS build-php # Build the dev image with xdebug FROM build-environment AS build-dev -RUN pecl install xdebug-3.5.0 && cp "$(php -r 'echo ini_get("extension_dir");')"/xdebug.so /tmp/xdebug.so +ARG PHP_VERSION +# xdebug's latest release (3.5.3) supports PHP up to 8.5: use its main branch (pinned) for PHP 8.6 +RUN if [ "${PHP_VERSION}" -ge 86 ]; then \ + mkdir -p /tmp/xdebug && cd /tmp/xdebug \ + && curl --location --silent --show-error --fail --retry 3 https://github.com/xdebug/xdebug/archive/64007df3a0925808022fb87b6c6f06febf058ee2.tar.gz \ + | tar xzC . --strip-components=1 \ + && phpize && ./configure --enable-xdebug && make && make install && cd / && rm -rf /tmp/xdebug; \ + else \ + pecl install xdebug-3.5.0; \ + fi; \ + cp "$(php -r 'echo ini_get("extension_dir");')"/xdebug.so /tmp/xdebug.so FROM php AS dev diff --git a/Makefile b/Makefile index f0bd70ac..768da898 100644 --- a/Makefile +++ b/Makefile @@ -30,13 +30,13 @@ default: docker-images # Build Docker images *locally* -docker-images: docker-images-php-83 docker-images-php-84 docker-images-php-85 +docker-images: docker-images-php-83 docker-images-php-84 docker-images-php-85 docker-images-php-86 docker-images-php-%: PHP_VERSION=$* ${BAKE_COMMAND} --load # Build and publish multi-architecture images to Docker Hub. -upload-to-docker-hub: upload-to-docker-hub-php-83 upload-to-docker-hub-php-84 upload-to-docker-hub-php-85 +upload-to-docker-hub: upload-to-docker-hub-php-83 upload-to-docker-hub-php-84 upload-to-docker-hub-php-85 upload-to-docker-hub-php-86 upload-to-docker-hub-php-%: # Make sure we have defined the docker tag (test $(DOCKER_TAG)) && echo "Tagging images with \"${DOCKER_TAG}\"" || echo "You have to define environment variable DOCKER_TAG" @@ -48,12 +48,12 @@ upload-to-docker-hub-php-%: --set "php-dev.tags=bref/php-$*-dev:4" --set "php-dev.tags=bref/php-$*-dev:${DOCKER_TAG}" --set "php-dev.tags=bref/php-$*-dev:latest" -test: test-83 test-84 test-85 +test: test-83 test-84 test-85 test-86 test-%: cd tests && $(MAKE) test-$* -clean: clean-83 clean-84 clean-85 +clean: clean-83 clean-84 clean-85 clean-86 # Clear the build cache, else all images will be rebuilt using cached layers docker builder prune clean-%: diff --git a/docker-bake.hcl b/docker-bake.hcl index 98f14f8e..f48edd04 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -17,6 +17,8 @@ variable "VERSIONS" { "83" = "8.3.36" "84" = "8.4.27" "85" = "8.5.12" + # Release candidate: final release planned for late November 2026 + "86" = "8.6.0RC5" } } diff --git a/src/cli-fpm/php-86.patch b/src/cli-fpm/php-86.patch new file mode 100644 index 00000000..d934d528 --- /dev/null +++ b/src/cli-fpm/php-86.patch @@ -0,0 +1,314 @@ +--enable-cli-fpm: link the FPM SAPI into the CLI binary (`php --fpm`, or `php` invoked as `php-fpm`). +Diff of https://github.com/php/php-src/pull/23558 (commit d0b32261e1, not merged yet), without its +NEWS/UPGRADING changes, plus (at the end) the rename of FPM's apache_request_headers() implementation +to fpm_request_headers(), as in the 8.5 backport: master has it, the PHP-8.6 branch does not, and the +CLI server defines the same C symbol. Applies to PHP 8.6.0RC5. + +diff --git a/sapi/cli/config.m4 b/sapi/cli/config.m4 +index 6abaa88df419..26b5b81a250f 100644 +--- a/sapi/cli/config.m4 ++++ b/sapi/cli/config.m4 +@@ -5,6 +5,22 @@ PHP_ARG_ENABLE([cli], + [yes], + [no]) + ++PHP_ARG_ENABLE([cli-fpm], ++ [whether to link FPM into the CLI binary], ++ [AS_HELP_STRING([--enable-cli-fpm], ++ [Link the FPM SAPI into the CLI binary, so that "php --fpm" runs php-fpm ++ (requires --enable-fpm)])], ++ [no], ++ [no]) ++ ++if test "$PHP_CLI_FPM" != "no"; then ++ if test "$PHP_CLI" = "no" || test "$PHP_FPM" = "no"; then ++ AC_MSG_ERROR([--enable-cli-fpm requires both the CLI and the FPM SAPI]) ++ fi ++ AC_DEFINE([PHP_CLI_WITH_FPM], [1], ++ [Define to 1 if the FPM SAPI is linked into the CLI binary.]) ++fi ++ + dnl The embed SAPI requires the CLI sources for do_php_cli(). + if test "$PHP_EMBED" != "no" -a "$PHP_CLI" = "no"; then + AC_MSG_ERROR([--enable-embed requires the CLI SAPI, do not use --disable-cli with --enable-embed]) +@@ -47,6 +63,8 @@ if test "$PHP_CLI" != "no"; then + [-DZEND_ENABLE_STATIC_TSRMLS_CACHE=1], + [PHP_CLI_SHARED_OBJS]) + PHP_CLI_OBJS="$PHP_CLI_OBJS $PHP_CLI_SHARED_OBJS" ++ AS_VAR_IF([PHP_CLI_FPM], [no],, ++ [PHP_CLI_OBJS="$PHP_CLI_OBJS \$(PHP_FASTCGI_OBJS) \$(PHP_FPM_SHARED_OBJS)"]) + + AS_CASE([$host_alias], + [*aix*], [ +diff --git a/sapi/cli/php.1.in b/sapi/cli/php.1.in +index 30626015ce77..1972b1f87b4c 100644 +--- a/sapi/cli/php.1.in ++++ b/sapi/cli/php.1.in +@@ -365,6 +365,15 @@ Shows configuration for extension + .TP + .B \-\-ini + Show configuration file names ++.TP ++.B \-\-fpm ++Run as ++.BR php\-fpm (8), ++passing the remaining arguments to it. Only available when PHP was configured ++with \-\-enable\-cli\-fpm, and only recognized as the first argument. ++Such a binary also runs as ++.BR php\-fpm (8) ++when invoked under a name starting with php\-fpm, e.g. through a symbolic link. + .SH FILES + .TP 15 + .B php\-cli.ini +diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c +index 3702da89f9f0..f5604b96f64d 100644 +--- a/sapi/cli/php_cli.c ++++ b/sapi/cli/php_cli.c +@@ -490,6 +490,9 @@ static void php_cli_usage(char *argv0) + "\n" + " --ini Show configuration file names\n" + " --ini=diff Show INI entries that differ from the built-in default\n" ++#ifdef PHP_CLI_WITH_FPM ++ " --fpm Run as php-fpm, passing the remaining arguments to it\n" ++#endif + "\n" + " --rf Show information about function .\n" + " --rc Show information about class .\n" +diff --git a/sapi/cli/php_cli_main.c b/sapi/cli/php_cli_main.c +index 1030b5feb923..b13066610f85 100644 +--- a/sapi/cli/php_cli_main.c ++++ b/sapi/cli/php_cli_main.c +@@ -12,8 +12,26 @@ + + #include "php.h" + #include "cli.h" ++#ifdef PHP_CLI_WITH_FPM ++#include "sapi/fpm/fpm/fpm.h" ++#endif + + int main(int argc, char *argv[]) + { ++#ifdef PHP_CLI_WITH_FPM ++ /* Running as "php-fpm*" (e.g. a php-fpm symlink to php) or as ++ * "php --fpm [args]" runs the FPM SAPI. argv is passed as is because FPM ++ * re-executes it on reload; FPM options start after "--fpm". */ ++ if (argc > 0 && argv[0]) { ++ const char *name = strrchr(argv[0], '/'); ++ name = name ? name + 1 : argv[0]; ++ if (strncmp(name, "php-fpm", strlen("php-fpm")) == 0) { ++ return fpm_main(argc, argv, 1); ++ } ++ } ++ if (argc > 1 && strcmp(argv[1], "--fpm") == 0) { ++ return fpm_main(argc, argv, 2); ++ } ++#endif + return do_php_cli(argc, argv); + } +diff --git a/sapi/cli/tests/cli_fpm.phpt b/sapi/cli/tests/cli_fpm.phpt +new file mode 100644 +index 000000000000..0e15bc1e8eeb +--- /dev/null ++++ b/sapi/cli/tests/cli_fpm.phpt +@@ -0,0 +1,38 @@ ++--TEST-- ++php --fpm runs the FPM SAPI ++--SKIPIF-- ++&1"), 'fpm-fcgi')) { ++ die("skip PHP was not built with --enable-cli-fpm"); ++} ++?> ++--FILE-- ++ .*$/m', shell_exec("$php --fpm -n -i"), $m); ++var_dump($m[0]); ++ ++// Anywhere else it is an ordinary argument. ++var_dump(shell_exec("$php -n -r 'echo \$argv[1];' -- --fpm")); ++ ++// Running under a name starting with "php-fpm" also switches to the FPM SAPI. ++$dir = __DIR__ . '/cli_fpm'; ++@mkdir($dir); ++symlink(realpath(getenv('TEST_PHP_EXECUTABLE')), "$dir/php-fpm8"); ++preg_match('/^Server API => .*$/m', shell_exec(escapeshellarg("$dir/php-fpm8") . " -n -i"), $m); ++var_dump($m[0]); ++?> ++--CLEAN-- ++ ++--EXPECT-- ++string(25) "Server API => FPM/FastCGI" ++string(5) "--fpm" ++string(25) "Server API => FPM/FastCGI" +diff --git a/sapi/fpm/config.m4 b/sapi/fpm/config.m4 +index 89c53a0c4d28..b2c293833965 100644 +--- a/sapi/fpm/config.m4 ++++ b/sapi/fpm/config.m4 +@@ -1,10 +1,3 @@ +-PHP_ARG_ENABLE([fpm], +- [for FPM build], +- [AS_HELP_STRING([--enable-fpm], +- [Enable building of the fpm SAPI executable])], +- [no], +- [no]) +- + dnl Configure checks. + AC_DEFUN([PHP_FPM_CLOCK], [ + AC_CHECK_FUNCS([clock_gettime],, [ +@@ -473,9 +466,18 @@ if test "$PHP_FPM" != "no"; then + + PHP_SELECT_SAPI([fpm], + [program], +- [$PHP_FPM_FILES $PHP_FPM_TRACE_FILES $PHP_FPM_SD_FILES], ++ [php_fpm_main.c], + [-I$abs_srcdir/sapi/fpm -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1]) + ++ dnl Everything except the main() entry point, so that the CLI binary can link ++ dnl the same objects for fpm_main() (--enable-cli-fpm). ++ PHP_ADD_SOURCES_X([sapi/fpm], ++ [$PHP_FPM_FILES $PHP_FPM_TRACE_FILES $PHP_FPM_SD_FILES], ++ [-I$abs_srcdir/sapi/fpm -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1], ++ [PHP_FPM_SHARED_OBJS]) ++ PHP_FPM_OBJS="$PHP_FPM_OBJS $PHP_FPM_SHARED_OBJS" ++ PHP_SUBST([PHP_FPM_SHARED_OBJS]) ++ + AS_CASE([$host_alias], + [*aix*], [ + BUILD_FPM="echo '\#! .' > php.sym && echo >>php.sym && nm -BCpg \`echo \$(PHP_GLOBAL_OBJS) \$(PHP_BINARY_OBJS) \$(PHP_FPM_OBJS) | sed 's/\([A-Za-z0-9_]*\)\.lo/\1.o/g'\` | \$(AWK) '{ if (((\$\$2 == \"T\") || (\$\$2 == \"D\") || (\$\$2 == \"B\")) && (substr(\$\$3,1,1) != \".\")) { print \$\$3 } }' | sort -u >> php.sym && \$(LIBTOOL) --tag=CC --mode=link \$(CC) -export-dynamic \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS_PROGRAM) \$(LDFLAGS) -Wl,-brtl -Wl,-bE:php.sym \$(PHP_RPATHS) \$(PHP_GLOBAL_OBJS) \$(PHP_BINARY_OBJS) \$(PHP_FASTCGI_OBJS) \$(PHP_FPM_OBJS) \$(EXTRA_LIBS) \$(FPM_EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_FPM_PATH)" +@@ -489,4 +491,5 @@ if test "$PHP_FPM" != "no"; then + PHP_SUBST([SAPI_FPM_PATH]) + PHP_SUBST([BUILD_FPM]) + PHP_SUBST([FPM_EXTRA_LIBS]) ++ AS_VAR_IF([PHP_CLI_FPM], [no],, [EXTRA_LIBS="$EXTRA_LIBS $FPM_EXTRA_LIBS"]) + fi +diff --git a/sapi/fpm/config0.m4 b/sapi/fpm/config0.m4 +new file mode 100644 +index 000000000000..d00da52b30e8 +--- /dev/null ++++ b/sapi/fpm/config0.m4 +@@ -0,0 +1,6 @@ ++PHP_ARG_ENABLE([fpm], ++ [for FPM build], ++ [AS_HELP_STRING([--enable-fpm], ++ [Enable building of the fpm SAPI executable])], ++ [no], ++ [no]) +diff --git a/sapi/fpm/fpm/fpm.h b/sapi/fpm/fpm/fpm.h +index ec036a2d6819..a018948c8bd2 100644 +--- a/sapi/fpm/fpm/fpm.h ++++ b/sapi/fpm/fpm/fpm.h +@@ -41,6 +41,10 @@ enum fpm_init_return_status { + }; + + int fpm_run(int *max_requests); ++/* this performs full fpm-SAPI boot: the former main() of php-fpm. ++ * argv must be the process' original argv (it is re-executed on reload), ++ * FPM options are parsed starting at argv[first_arg]. */ ++int fpm_main(int argc, char *argv[], int first_arg); + enum fpm_init_return_status fpm_init(int argc, char **argv, char *config, char *prefix, char *pid, int test_conf, int run_as_root, int force_daemon, int force_stderr); + + struct fpm_globals_s { +diff --git a/sapi/fpm/fpm/fpm_main.c b/sapi/fpm/fpm/fpm_main.c +index 3d35e942a06e..d08ad1a640c2 100644 +--- a/sapi/fpm/fpm/fpm_main.c ++++ b/sapi/fpm/fpm/fpm_main.c +@@ -1530,8 +1530,8 @@ static zend_module_entry cgi_module_entry = { + STANDARD_MODULE_PROPERTIES + }; + +-/* {{{ main */ +-int main(int argc, char *argv[]) ++/* {{{ fpm_main */ ++int fpm_main(int argc, char *argv[], int first_arg) + { + int exit_status = FPM_EXIT_OK; + int c, use_extended_info = 0; +@@ -1592,6 +1592,7 @@ int main(int argc, char *argv[]) + + php_ini_builder_init(&ini_builder); + ++ php_optind = first_arg; + while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) { + switch (c) { + case 'c': +diff --git a/sapi/fpm/php_fpm_main.c b/sapi/fpm/php_fpm_main.c +new file mode 100644 +index 000000000000..ab06cb4347d0 +--- /dev/null ++++ b/sapi/fpm/php_fpm_main.c +@@ -0,0 +1,19 @@ ++/* ++ +----------------------------------------------------------------------+ ++ | Copyright © The PHP Group and Contributors. | ++ +----------------------------------------------------------------------+ ++ | This source file is subject to the Modified BSD License that is | ++ | bundled with this package in the file LICENSE, and is available | ++ | through the World Wide Web at . | ++ | | ++ | SPDX-License-Identifier: BSD-3-Clause | ++ +----------------------------------------------------------------------+ ++*/ ++ ++#include "php.h" ++#include "fpm/fpm.h" ++ ++int main(int argc, char *argv[]) ++{ ++ return fpm_main(argc, argv, 1); ++} +diff -ru a/sapi/fpm/fpm/fpm_main.c b/sapi/fpm/fpm/fpm_main.c +--- a/sapi/fpm/fpm/fpm_main.c 2026-11-04 11:29:36 ++++ b/sapi/fpm/fpm/fpm_main.c 2026-11-04 11:29:49 +@@ -1495,7 +1495,7 @@ + } + /* }}} */ + +-PHP_FUNCTION(apache_request_headers) /* {{{ */ ++PHP_FUNCTION(fpm_request_headers) /* {{{ */ + { + fcgi_request *request; + +diff -ru a/sapi/fpm/fpm/fpm_main.stub.php b/sapi/fpm/fpm/fpm_main.stub.php +--- a/sapi/fpm/fpm/fpm_main.stub.php 2026-11-04 11:29:36 ++++ b/sapi/fpm/fpm/fpm_main.stub.php 2026-11-04 11:29:50 +@@ -4,9 +4,10 @@ + + function fastcgi_finish_request(): bool {} + ++/** @implementation-alias fpm_request_headers */ + function apache_request_headers(): array {} + +-/** @alias apache_request_headers */ ++/** @implementation-alias fpm_request_headers */ + function getallheaders(): array {} + + function fpm_get_status(): array|false {} +diff -ru a/sapi/fpm/fpm/fpm_main_arginfo.h b/sapi/fpm/fpm/fpm_main_arginfo.h +--- a/sapi/fpm/fpm/fpm_main_arginfo.h 2026-11-04 11:29:36 ++++ b/sapi/fpm/fpm/fpm_main_arginfo.h 2026-11-04 11:29:50 +@@ -13,13 +13,13 @@ + ZEND_END_ARG_INFO() + + ZEND_FUNCTION(fastcgi_finish_request); +-ZEND_FUNCTION(apache_request_headers); ++ZEND_FUNCTION(fpm_request_headers); + ZEND_FUNCTION(fpm_get_status); + + static const zend_function_entry ext_functions[] = { + ZEND_FE(fastcgi_finish_request, arginfo_fastcgi_finish_request) +- ZEND_FE(apache_request_headers, arginfo_apache_request_headers) +- ZEND_RAW_FENTRY("getallheaders", zif_apache_request_headers, arginfo_getallheaders, 0, NULL, NULL) ++ ZEND_RAW_FENTRY("apache_request_headers", zif_fpm_request_headers, arginfo_apache_request_headers, 0, NULL, NULL) ++ ZEND_RAW_FENTRY("getallheaders", zif_fpm_request_headers, arginfo_getallheaders, 0, NULL, NULL) + ZEND_FE(fpm_get_status, arginfo_fpm_get_status) + ZEND_FE_END + }; diff --git a/tests/Makefile b/tests/Makefile index 401d9971..3f68d90d 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,5 +1,5 @@ -test: test-83 test-84 test-85 +test: test-83 test-84 test-85 test-86 # This rule matches with a wildcard, for example `test-84`. # The `$*` variable will contained the matched part, in this case `84`. From 182675b0a9fcae8b9ca5929316df858fc08eb628 Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Mon, 23 Nov 2026 10:37:03 +0100 Subject: [PATCH 3/3] Install patch: the cli-fpm patch needs it --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index b7c7562b..c8898622 100644 --- a/Dockerfile +++ b/Dockerfile @@ -40,6 +40,8 @@ RUN set -xe; \ gcc \ g++ \ make \ + # Applies the cli-fpm patch to PHP's source (src/cli-fpm) + patch \ # Finds the libraries below for ./configure pkg-config \ # Headers of the libraries PHP and its extensions use (runtime libraries in the `php` stage below)