镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Link the CLI into php-fpm, so that a php symlink to php-fpm runs the CLI - #24192

Open
mnapoli wants to merge 2 commits into
php:masterfrom
mnapoli:fpm-with-cli
Open

mnapoli wants to merge 2 commits into
php:masterfrom
mnapoli:fpm-with-cli

Conversation

@mnapoli

@mnapoli mnapoli commented Oct 8, 2026 •

Copy link
Copy Markdown

This is an alternative to #23558, which it would replace, following the discussion of the RFC on internals: https://externals.io/message/132806

I will update the RFC (https://wiki.php.net/rfc/single-binary-cli-fpm) if feedback is positive here and the mailing list.

Instead of linking FPM into the php CLI binary, this links the CLI into php-fpm, as suggested by Nicolas Grekas and Jakub Zelenka. Larry Garfield pointed out that the first approach privileged FPM inside the CLI binary. Here the php binary is unchanged, and the same approach can be used by any other SAPI that wants to ship the CLI (like FrankenPHP does through embed since #21385).

When the CLI SAPI is built, its objects (PHP_CLI_SHARED_OBJS, introduced by #21385) are linked into php-fpm. php-fpm then runs as the CLI when invoked under the name php, optionally followed by a digit:

php-fpm -y /etc/php-fpm.conf   # FPM, as today

ln -s php-fpm php
./php script.php               # CLI
ln -s php-fpm php8.7
./php8.7 -v                    # CLI

Under any other name (php-fpm, php-fpm8.7, php-cgi…), php-fpm behaves as before.

Design

  • No configure option: the CLI is linked into php-fpm whenever the CLI SAPI is built, which is the default. The CLI has no libraries of its own, so php-fpm gains no dependency, only the CLI code (about 150 KB on a minimal build). With --disable-cli, php-fpm is built as before.
  • The mode is selected by the executable name only, there is no flag. FPM's argument parsing is untouched (no clash between the CLI and FPM options, such as -F), and argv reaches the CLI unchanged.
  • The name rule is php, optionally followed by a digit (php8.3 on Debian, php83 on Alpine), so that php-cgi, phpdbg, phpize, etc. are not affected.
  • Both SAPIs define PHP_FUNCTION(apache_request_headers), which is a duplicate symbol once linked together. FPM's C symbol is renamed to fpm_request_headers (the name suggested in the review of Add --enable-cli-fpm to link the FPM SAPI into the CLI binary (php --fpm) #23558), in a separate commit. The PHP functions are unchanged.

Shipping a single executable

PHP_BINARY is resolved with realpath(). To ship a single executable for both SAPIs, install the php-fpm binary as php, and php-fpm as a symlink to it. In CLI mode, PHP_BINARY then points to php, so scripts that run PHP_BINARY (Composer restarting itself, PHPUnit process isolation…) keep running the CLI. With the opposite layout (php as a symlink to php-fpm), they would start FPM. This is documented in UPGRADING.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant