镜像站点 · 本页由第三方 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
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ PHP NEWS
- FPM:
. Use recommended TYPE, HELP order for OpenMetrics metadata.
(Marcel Hernandez)
. php-fpm now includes the CLI SAPI when it is built, and runs as the CLI
when invoked as php (e.g. through a php symlink). (Matthieu Napoli)

- Hash:
. Fixed mhash_keygen_s2k() truncating a $length above INT_MAX instead of
Expand Down
10 changes: 10 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ PHP 8.7 UPGRADE NOTES
3. Changes in SAPI modules
========================================

- FPM:
. When the CLI SAPI is built, it is also linked into php-fpm. php-fpm then
runs as the CLI when invoked under the name "php", optionally followed by
a digit (e.g. php, php8.7 or php87), typically through a symlink. Under
any other name, php-fpm behaves as before.
To ship a single executable for both SAPIs, install the php-fpm binary as
php and make php-fpm a symlink to it: PHP_BINARY is resolved to the real
file, so scripts that run PHP_BINARY (e.g. to restart themselves) keep
running the CLI.

========================================
4. Deprecated Functionality
========================================
Expand Down
2 changes: 2 additions & 0 deletions UPGRADING.INTERNALS
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ PHP 8.7 INTERNALS UPGRADE NOTES

- Unix build system changes:
. Autoconf minimum required version upgraded to 2.71.
. When the CLI SAPI is built, PHP_FPM_OBJS includes PHP_CLI_SHARED_OBJS and
PHP_FPM_WITH_CLI is defined, so that php-fpm can run do_php_cli().

========================
3. Module changes
Expand Down
8 changes: 8 additions & 0 deletions sapi/fpm/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,14 @@ if test "$PHP_FPM" != "no"; then
[$PHP_FPM_FILES $PHP_FPM_TRACE_FILES $PHP_FPM_SD_FILES],
[-I$abs_srcdir/sapi/fpm -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1])

dnl Link the CLI objects into php-fpm for do_php_cli(), so that php-fpm runs as
dnl the CLI when invoked under a "php" name (e.g. a php symlink to php-fpm).
AS_VAR_IF([PHP_CLI], [no],, [
AC_DEFINE([PHP_FPM_WITH_CLI], [1],
[Define to 1 if the CLI SAPI is linked into the FPM binary.])
PHP_FPM_OBJS="$PHP_FPM_OBJS $PHP_CLI_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)"
Expand Down
16 changes: 16 additions & 0 deletions sapi/fpm/fpm/fpm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ int __riscosify_control = __RISCOSIFY_STRICT_UNIX_SPECS;

#include <php_config.h>
#include "fpm.h"
#ifdef PHP_FPM_WITH_CLI
#include "sapi/cli/cli.h"
#endif
#include "fpm_main_arginfo.h"
#include "fpm_request.h"
#include "fpm_status.h"
Expand Down Expand Up @@ -1559,6 +1562,19 @@ int main(int argc, char *argv[])
bool old_rc_debug;
#endif

#ifdef PHP_FPM_WITH_CLI
/* Invoked as "php", "php8.7", "php87"... (e.g. a php symlink to php-fpm):
* run the CLI SAPI instead. */
if (argc > 0 && argv[0]) {
const char *name = strrchr(argv[0], '/');
name = name ? name + 1 : argv[0];
if (strncmp(name, "php", strlen("php")) == 0
&& (name[3] == '\0' || isdigit((unsigned char) name[3]))) {
return do_php_cli(argc, argv);
}
}
#endif

#if defined(SIGPIPE) && defined(SIG_IGN)
signal(SIGPIPE, SIG_IGN); /* ignore SIGPIPE in standalone mode so
that sockets created via fsockopen()
Expand Down
4 changes: 4 additions & 0 deletions sapi/fpm/php-fpm.8.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ php-fpm \- PHP FastCGI Process Manager 'PHP-FPM'
Web development and can be embedded into HTML. This is a variant of PHP that will run in the background as a daemon, listening for CGI requests. Output is logged to @php_fpm_localstatedir@/log/php-fpm.log.
.LP
Most options are set in the configuration file. The configuration file is @php_fpm_sysconfdir@/php-fpm.conf. By default, php-fpm will respond to CGI requests listening on localhost http port 9000. Therefore php-fpm expects your webserver to forward all requests for '.php' files to port 9000 and you should edit your webserver configuration file appropriately.
.LP
When PHP was built with the CLI SAPI, php-fpm runs as
.BR php (1)
instead when invoked under the name php, optionally followed by a digit (e.g. php8.7), typically through a symbolic link.
.SH OPTIONS
.TP 15
.B \-C
Expand Down
41 changes: 41 additions & 0 deletions sapi/fpm/tests/main-cli.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
--TEST--
FPM: runs as the CLI when invoked under a php name
--SKIPIF--
<?php
include "skipif.inc";
$php = \FPM\Tester::findExecutable();
if (preg_match("/'--(disable-cli|enable-cli=no)'/", (string) shell_exec("$php -n -i"))) {
die("skip the CLI SAPI was not built");
}
?>
--FILE--
<?php

require_once "tester.inc";

$fpm = \FPM\Tester::findExecutable();
$dir = __DIR__ . '/main-cli';
@mkdir($dir);

foreach (['php', 'php8', 'php-cgi'] as $name) {
@unlink("$dir/$name");
symlink($fpm, "$dir/$name");
echo "$name: ", trim(shell_exec(escapeshellarg("$dir/$name") . " -n -r 'echo PHP_SAPI;' 2>&1 | head -1")), "\n";
}

echo "php-fpm: ", trim(shell_exec(escapeshellarg($fpm) . " -n -r 'echo PHP_SAPI;' 2>&1 | head -1")), "\n";

?>
--CLEAN--
<?php
$dir = __DIR__ . '/main-cli';
foreach (['php', 'php8', 'php-cgi'] as $name) {
@unlink("$dir/$name");
}
@rmdir($dir);
?>
--EXPECTF--
php: cli
php8: cli
php-cgi: Usage: php-cgi [%s
php-fpm: Usage: php-fpm [%s
Loading