Add --enable-cli-fpm to link the FPM SAPI into the CLI binary (php --fpm) - #23558
Open
mnapoli wants to merge 1 commit into
Open
Add --enable-cli-fpm to link the FPM SAPI into the CLI binary (php --fpm)#23558mnapoli wants to merge 1 commit into
--enable-cli-fpm to link the FPM SAPI into the CLI binary (php --fpm)#23558mnapoli wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds an opt-in configure option,
--enable-cli-fpm, that links the FPM SAPI into thephpbinary.The binary behaves exactly like the CLI unless its first argument is
--fpm, in which case it runs the php-fpm master with the remaining arguments:The default build is unchanged: without the flag,
phpandphp-fpmare built exactly as before.Goal
In some environments, the size of the runtime matters. Having
phpandphp-fpmbinaries when they are ~99% the same code can be wasteful.That's the case for example on AWS Lambda with Bref, where a second ~24 MB binary on disk increases the cold start duration (because that's more data to load in the container/micro-VM when it starts).
Design
This follows the shape of #21385 (
do_php_cli()/PHP_CLI_SHARED_OBJSfor embed):sapi/fpm/fpm/fpm_main.c:main()becomesdo_php_fpm(), declared infpm.h. A newsapi/fpm/php_fpm_main.cholds the one-linemain()for the standalonephp-fpmbinary.sapi/fpm/config.m4:PHP_SELECT_SAPInow only takesphp_fpm_main.c; all other FPM sources go throughPHP_ADD_SOURCES_XintoPHP_FPM_SHARED_OBJS, which is appended toPHP_FPM_OBJS. TheBUILD_FPMlink lines are untouched.sapi/fpm/config0.m4(new):PHP_ARG_ENABLE([fpm])moves here so$PHP_FPMis set beforesapi/cli/config.m4runs (same reason embed has aconfig0.m4).sapi/cli/config.m4:PHP_ARG_ENABLE([cli-fpm]), default off; errors out unless both the CLI and FPM SAPIs are enabled; definesPHP_CLI_WITH_FPMand appends$(PHP_FASTCGI_OBJS) $(PHP_FPM_SHARED_OBJS)toPHP_CLI_OBJS. TheBUILD_CLIlines are untouched.FPM_EXTRA_LIBS(systemd, acl, apparmor, selinux) is appended toEXTRA_LIBSwhen the flag is on.sapi/cli/php_cli_main.c: under#ifdef PHP_CLI_WITH_FPM, dispatch todo_php_fpm(argc, argv)whenargv[1]is--fpm.--fpm, so argv is passed through unchanged. Shifting argv instead breaks FPM's process titles (fpm_env_init_mainrequires the argv strings to be contiguous), which I verified on Linux. Side effect:php-fpm --fpmis silently accepted.PHP_FUNCTION(apache_request_headers), which is a duplicate-symbol link error when linked together. FPM's C symbol is renamed tofpm_apache_request_headers; the stub uses@implementation-aliason bothapache_request_headers()andgetallheaders()and the arginfo header is regenerated. Userland names and behaviour are unchanged.php --help,php.1, NEWS, UPGRADING and UPGRADING.INTERNALS are updated. A newsapi/cli/tests/cli_fpm.phptskips unless the flag is built in.Backward compatibility
main()of php-fpm is nowdo_php_fpm();--enable-fpmis declared inconfig0.m4. Both noted in UPGRADING.INTERNALS.Note: I am new here, so please let me know if I've got things backwards, I've made mistakes, I haven't followed the right workflow, etc. I'm opening this tentatively to get the discussion started.
And the main question I see: does this require a RFC or not?