From 94a2135ac45cd723c4086e15e9982113a9a655fa Mon Sep 17 00:00:00 2001 From: Jakub Zelenka Date: Fri, 10 Oct 2025 16:21:45 +0200 Subject: [PATCH] Fix GH-19989: PHP 8.5 FPM access log lines also go to STDERR This was due to not omitting logging using external_log --- sapi/fpm/fpm/zlog.c | 4 +- sapi/fpm/fpm/zlog.h | 1 + .../tests/gh19989-access-log-fcgi-stderr.phpt | 47 +++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 sapi/fpm/tests/gh19989-access-log-fcgi-stderr.phpt diff --git a/sapi/fpm/fpm/zlog.c b/sapi/fpm/fpm/zlog.c index 803a768234bd6..b34d455e6bd6c 100644 --- a/sapi/fpm/fpm/zlog.c +++ b/sapi/fpm/fpm/zlog.c @@ -466,7 +466,7 @@ static ssize_t zlog_stream_buf_flush(struct zlog_stream *stream) /* {{{ */ } #endif - if (external_logger != NULL) { + if (stream->use_external_logger) { external_logger(stream->flags & ZLOG_LEVEL_MASK, stream->buf.data + stream->prefix_len, stream->len - stream->prefix_len); } @@ -539,9 +539,11 @@ static inline void zlog_stream_init_internal( stream->fd = fd > -1 ? fd : STDERR_FILENO; stream->buf_init_size = capacity; if (flags & ZLOG_ACCESS_LOG) { + stream->use_external_logger = 0; stream->use_buffer = 1; stream->use_stderr = fd < 0; } else { + stream->use_external_logger = external_logger != NULL; stream->use_buffer = zlog_buffering || external_logger != NULL || stream->use_syslog; stream->use_stderr = fd < 0 || ( diff --git a/sapi/fpm/fpm/zlog.h b/sapi/fpm/fpm/zlog.h index 6886a0ae807da..8b4a80155f073 100644 --- a/sapi/fpm/fpm/zlog.h +++ b/sapi/fpm/fpm/zlog.h @@ -77,6 +77,7 @@ struct zlog_stream { unsigned int decorate:1; unsigned int is_stdout:1; unsigned int over_limit:1; + unsigned int use_external_logger:1; int fd; int line; int child_pid; diff --git a/sapi/fpm/tests/gh19989-access-log-fcgi-stderr.phpt b/sapi/fpm/tests/gh19989-access-log-fcgi-stderr.phpt new file mode 100644 index 0000000000000..6875774de3fac --- /dev/null +++ b/sapi/fpm/tests/gh19989-access-log-fcgi-stderr.phpt @@ -0,0 +1,47 @@ +--TEST-- +FPM: GH-19989 - Access log going to fcgi error stream +--SKIPIF-- + +--FILE-- +start(['--prefix', $prefix]); +$tester->expectLogStartNotices(); +$response = $tester->request()->expectBody('OK'); +$response->expectNoError(); +$tester->expectAccessLog("'GET /gh19989-access-log-fcgi-stderr.src.php' 200"); +$tester->terminate(); +$tester->expectLogTerminatingNotices(); +$tester->close(); +$tester->checkAccessLog(); + +?> +Done +--EXPECT-- +Done +--CLEAN-- +