php-fpm workers' log get silenced with config `catch_workers_output = yes` and `error_log = syslog`
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 70/100
Hướng nghiên cứu
Investigate sapi/fpm/fpm/fpm_stdio.c and zlog.c where stderr is hardcoded instead of using zlog() when error_log=syslog. First read fpm_stdio.c around line 195 and trace master process logging. Done when php-fpm with catch_workers_output=yes emits worker errors to syslog/journald.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
Follow up of Syslog broken on FPM since PHP 7.3.0 https://bugs.php.net/bug.php?id=79342.
When the php-fpm config catch_workers_output is enabled, and error_log is syslog, all workers' log won't go syslog.
I saw /proc/<php-fpm master pid>/fd/2 points to /dev/null, this is expected as
https://github.com/php/php-src/blob/136e049ac10b032c83018e65b63b6df858943750/sapi/fpm/fpm/fpm_stdio.c#L130-L132
https://github.com/php/php-src/blob/136e049ac10b032c83018e65b63b6df858943750/sapi/fpm/fpm/fpm_stdio.c#L63-L66
https://github.com/php/php-src/blob/136e049ac10b032c83018e65b63b6df858943750/sapi/fpm/fpm/fpm.c#L82
point stderr to stdout when php-fpm config error_log = syslog, and stdout was previously pointed to /dev/null:
https://github.com/php/php-src/blob/136e049ac10b032c83018e65b63b6df858943750/sapi/fpm/fpm/fpm_stdio.c#L27-L36
https://github.com/php/php-src/blob/136e049ac10b032c83018e65b63b6df858943750/sapi/fpm/fpm/fpm.c#L57
This was introduced in #1432 to fix https://bugs.php.net/bug.php?id=69865.
Also I guess this can prevent seeing duplicate logs from php-fpm in journalctl when using systemd service unit with the default value journal of option StandardError= to run php-fpm with daemonize = off as php-fpm itself already reporting logs to syslog and journald should be syslogd on many distros using systemd.
With php-fpm config catch_workers_output = yes, all workers' stderr are piped to master process, assume one of the worker's pid is 404:
$ ls -l /proc/404/fd/2
l-wx------ 1 root root 64 Oct 31 05:58 /proc/404/fd/2 -> 'pipe:[1853673300]'
$ find /proc -lname 'pipe:\[1853673300]' 2>/dev/null # https://superuser.com/q/401066/1777086#comment2862240_401619
/proc/317/task/317/fd/11
/proc/317/fd/11
/proc/404/task/404/fd/2
/proc/404/fd/2
$ lsof -d ^mem -a -p 317 # fd used by master process
So workers' stderr such as PHP error should be pipe to master process and then journald via syslog, but there's only log from master process in journalctl -u <php-fpm unit name>, such as NOTICE: ready to handle connections.
When I strace into the master process:
$ echo '<?php 1' > test.php
$ strace -p 317 -e read,write -vs 999 &
strace: Process 317 attached
$ SCRIPT_FILENAME=$PWD/test.php REQUEST_METHOD=GET cgi-fcgi -bind -connect localhost:9000 # or path to unix domain socket of php-fpm
Status: 500 Internal Server Error
Content-type: text/html; charset=UTF-8
read(11
, "NOTICE: PHP message: PHP Parse error: syntax error, unexpected end of file in /foo/bar/test.php on line 2\n\0fscf\0", 1023) = 113
write(2, "[31-Oct-2026 06:41:53] WARNING: [pool roundcube] child 407 said into stderr: \"NOTICE: PHP message: PHP Parse error: syntax error, unexpected end of file in /foo/bar/test.php on line 2\"\n", 186) = 186
read(11, 0x7fff1dc02980, 1023) = -1 EAGAIN (Resource temporarily unavailable)
it just pipe the fd/11 that piped from worker process's stderr to its stderr, which is /dev/null.
I guess it's caused by this hardcoded stderr destination:
https://github.com/php/php-src/blob/136e049ac10b032c83018e65b63b6df858943750/sapi/fpm/fpm/fpm_stdio.c#L195
https://github.com/php/php-src/blob/136e049ac10b032c83018e65b63b6df858943750/sapi/fpm/fpm/zlog.c#L528-L556
that introduced in commit https://github.com/php/php-src/commit/3e5afbf0a80317216d98c6e5c0dd2eb54f34e438#diff-5af9050ab2bfafe95720d7badd345919c64c8fcd41a16089facf80a439ce86b0R144 of #2458 which appeared in https://github.com/php/php-src/releases/tag/php-7.3.0RC1, before that it's using zlog():
https://github.com/php/php-src/blob/2a78006adb42ac535fa3ac373170181859cccbf5/sapi/fpm/fpm/fpm_stdio.c#L189-L190
https://github.com/php/php-src/blob/2a78006adb42ac535fa3ac373170181859cccbf5/sapi/fpm/fpm/zlog.h#L9
https://github.com/php/php-src/blob/2a78006adb42ac535fa3ac373170181859cccbf5/sapi/fpm/fpm/zlog.c#L198-L201
which supports writing to syslog:
https://github.com/php/php-src/blob/2a78006adb42ac535fa3ac373170181859cccbf5/sapi/fpm/fpm/zlog.c#L129-L138
when error_log = syslog:
https://github.com/php/php-src/blob/2a78006adb42ac535fa3ac373170181859cccbf5/sapi/fpm/fpm/fpm_stdio.c#L286-L299
PHP Version
PHP 8.5.12 (fpm-fcgi) (built: Oct 19 2026 17:02:46) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.5.12, Copyright (c) Zend Technologies
with Zend OPcache v8.5.12, Copyright (c), by Zend Technologies
Operating System
No response
- Ngôn ngữ chính
- C
- Star
- 41.8k
- Fork
- 8.5k
- Merge trung bình
- 2 ngày 13 giờ
- Pull request đã merge (30 ngày)
- 145
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của php/php-src
-
ext/openssl: 8.2.31+/8.3.31+ fail to build against OpenSSL 1.0.2 (ASN1_STRING_get0_data in xp_ssl.c)Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Bug Status: Needs Triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
php/php-src#25397 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
SNMP accepts malformed remote portsCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 62/100
php/php-src#25137 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Bug Status: Needs Triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
Maintainer thường phản hồi trong vòng 1 ngày
-
quoted_printable_encode() produces lines longer than 76 characters for bytes 0xF5 to 0xFFCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
not for AI lovers
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
OSGeo/gdal#15515 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Template: Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
betaflight/betaflight#16014 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 75/100
ly05010419/MacNativeGames#2119 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100