镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 8.7.0alpha1

- CLI:
. Added the --enable-cli-fpm configure option, which links the FPM SAPI into
the php binary so that "php --fpm" (or a php-fpm symlink to php) runs
php-fpm. (Matthieu Napoli)

- Curl:
. curl_multi_exec() now throws a TypeError when still_running is not an int.
(arshidkv12)
Expand Down
7 changes: 7 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ PHP 8.7 UPGRADE NOTES
3. Changes in SAPI modules
========================================

- CLI:
. When PHP is configured with --enable-cli-fpm, the php binary also contains
the FPM SAPI: "php --fpm [php-fpm options]" behaves like php-fpm. The flag
is only recognized as the first argument. The binary also behaves like
php-fpm when invoked under a name starting with "php-fpm" (e.g. through a
php-fpm symlink). The default build is unchanged.

========================================
4. Deprecated Functionality
========================================
Expand Down
5 changes: 5 additions & 0 deletions UPGRADING.INTERNALS
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ PHP 8.7 INTERNALS UPGRADE NOTES
- The INIT_CLASS_ENTRY_INIT_METHODS() macro, which was previously used as
part of handling disabled classes, was removed following the removal of
the `disable_classes` INI setting in PHP 8.5.
- Added fpm_main(), the former main() of php-fpm.

========================
2. Build system changes
Expand All @@ -57,6 +58,10 @@ PHP 8.7 INTERNALS UPGRADE NOTES

- Unix build system changes:
. Autoconf minimum required version upgraded to 2.71.
. The --enable-fpm option moved to sapi/fpm/config0.m4 so that other SAPIs
can test $PHP_FPM. The FPM sources other than the main() entry point are
now built into PHP_FPM_SHARED_OBJS. The new --enable-cli-fpm option links
them into the CLI binary.

========================
3. Module changes
Expand Down
18 changes: 18 additions & 0 deletions sapi/cli/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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*], [
Expand Down
9 changes: 9 additions & 0 deletions sapi/cli/php.1.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions sapi/cli/php_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <name> Show information about function <name>.\n"
" --rc <name> Show information about class <name>.\n"
Expand Down
18 changes: 18 additions & 0 deletions sapi/cli/php_cli_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
38 changes: 38 additions & 0 deletions sapi/cli/tests/cli_fpm.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
--TEST--
php --fpm runs the FPM SAPI
--SKIPIF--
<?php
include "skipif.inc";
$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');
if (!str_contains((string) shell_exec("$php --fpm -n -v 2>&1"), 'fpm-fcgi')) {
die("skip PHP was not built with --enable-cli-fpm");
}
?>
--FILE--
<?php
$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');

// As the first argument, --fpm switches to the FPM SAPI.
preg_match('/^Server API => .*$/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--
<?php
$dir = __DIR__ . '/cli_fpm';
@unlink("$dir/php-fpm8");
@rmdir($dir);
?>
--EXPECT--
string(25) "Server API => FPM/FastCGI"
string(5) "--fpm"
string(25) "Server API => FPM/FastCGI"
19 changes: 11 additions & 8 deletions sapi/fpm/config.m4
Original file line number Diff line number Diff line change
@@ -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],, [
Expand Down Expand Up @@ -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])
Comment on lines +472 to +479

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you I'm not sure this is a good idea. Does this mean that it will always created shared lib for php-fpm so it will no longer be a single binary?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No shared library is built. "SHARED" means shared between two SAPIs, following PHP_CLI_SHARED_OBJS naming from #21385. Happy to rename it (e.g. PHP_FPM_COMMON_OBJS) if you find it confusing.


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)"
Expand All @@ -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
6 changes: 6 additions & 0 deletions sapi/fpm/config0.m4
Original file line number Diff line number Diff line change
@@ -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])
4 changes: 4 additions & 0 deletions sapi/fpm/fpm/fpm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions sapi/fpm/fpm/fpm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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':
Expand Down
19 changes: 19 additions & 0 deletions sapi/fpm/php_fpm_main.c
Original file line number Diff line number Diff line change
@@ -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 <https://www.php.net/license/>. |
| |
| 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);
}
Loading