跳转到内容
View in the app

A better way to browse. Learn more.

彼岸论坛

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[问与答] PHP FPM 五分钟假死一次,没有任何报错

发表于

我的 Linux 服务器上搭建了 Nginx+PHP-FPM 的网站服务,从不知道什么时候开始,网站就经常 502 ,后来经过仔细观察发现每隔 5 分钟准时挂一次,具体表现为 /dev/shm/php-cgi.sock 消失,但 fpm 主进程和子进程都还在,Nginx 访问直接 502 。然后我想,可能是 PHP7 的问题,于是我又装了个 PHP8 ,结果还是一样 5 分钟挂一次,我就纳闷了。

我尝试把 PHP-FPM 的日志等级设置为 debug ,然后观察日志输出内容,网站访问正常的时候,日志输出大概如下:

[30-Aug-2024 09:03:56.136408] DEBUG: pid 3493523, fpm_event_loop(), line 430: event module triggered 1 events
[30-Aug-2024 09:03:56.798162] DEBUG: pid 3493523, fpm_pctl_perform_idle_server_maintenance(), line 382: [pool www] currently 0 active children, 256 spare children, 256 running children. Spawning rate 1
[30-Aug-2024 09:03:56.848024] DEBUG: pid 3493523, fpm_event_loop(), line 430: event module triggered 1 events
[30-Aug-2024 09:03:57.474479] DEBUG: pid 3493523, fpm_event_loop(), line 430: event module triggered 1 events
[30-Aug-2024 09:03:57.798815] DEBUG: pid 3493523, fpm_pctl_perform_idle_server_maintenance(), line 382: [pool www] currently 0 active children, 256 spare children, 256 running children. Spawning rate 1

但是每次挂掉的时候,就会持续输出下面这样的内容,此时 php-cgi.sock 就会消失,并且没有看到任何 WARNING 或者 ERROR 日志内容。

[30-Aug-2024 09:03:57.798815] DEBUG: pid 3493523, fpm_pctl_perform_idle_server_maintenance(), line 382: [pool www] currently 0 active children, 256 spare children, 256 running children. Spawning rate 1

我尝试过调整 php-fpm.conf 文件的 max_children 等配置,但是都没用,还是每 5 分钟准时挂一次。我又找来另一台服务器,用同样的系统,同样的 PHP 版本和配置,同样的 Nginx 配置,同样的访问流量,结果新的服务器啥事没有,甚至新的服务器配置比有问题的那台还低,这就奇怪了。

实在是想不到原因了,求助一下各位大佬,谢谢~


软硬件配置

  • PHP:7.4.30 NTS / PHP 8.2.7 NTS
  • Nginx:1.23.3
  • 系统:Fedora 37
  • CPU:E5-2696 v4 * 2 (有问题的)/ E5-2660 v2 * 2 (没问题的)
  • 内存:128G (有问题的)/ 64G (没问题的)
  • 硬盘:两台机器都有至少 1T 以上空闲空间

PHP-FPM 配置

https://gist.github.com/kasuganosoras/1d8611a42bcbba19363dcab3931bfd52

ulimit -a

real-time non-blocking time  (microseconds, -R) unlimited
core file size              (blocks, -c) unlimited
data seg size               (kbytes, -d) unlimited
scheduling priority                 (-e) 0
file size                   (blocks, -f) unlimited
pending signals                     (-i) 514500
max locked memory           (kbytes, -l) 8192
max memory size             (kbytes, -m) unlimited
open files                          (-n) 1000000
pipe size                (512 bytes, -p) 8
POSIX message queues         (bytes, -q) 819200
real-time priority                  (-r) 0
stack size                  (kbytes, -s) 8192
cpu time                   (seconds, -t) unlimited
max user processes                  (-u) 1000000
virtual memory              (kbytes, -v) unlimited
file locks                          (-x) unlimited

Featured Replies

No posts to show

创建帐户或登录来提出意见

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.