PHP-FPM and timeouts (503)



我的服务器运行Nginx + PHP-FPM设置时遇到了一些问题。本周,我们的用户在 02.00 CEST 左右看到了 503。从浏览器中,它在一定时间(超过几分钟的等待)后超时。我已经检查了日志,我唯一注意到的是下面日志的第一行:

 [20-Sep-2013 01:45:00] WARNING: [pool web1] server reached pm.max_children setting (25), consider raising it
    [20-Sep-2013 01:45:03] NOTICE: [pool web1] child 3657 exited with code 0 after 30.161697 seconds from start
    [20-Sep-2013 01:45:03] NOTICE: [pool web1] child 3672 started
    [20-Sep-2013 01:45:07] NOTICE: [pool web1] child 3655 exited with code 0 after 33.749738 seconds from start

当它超时时,我检查了每个进程的内存使用情况和计数,PHP-FPM 似乎有 26 个进程正在运行。

重新启动 PHP-FPM 有所帮助。以下是重新启动后的 FPM 日志:

[20-Sep-2013 07:28:41] NOTICE: Terminating ...
[20-Sep-2013 07:28:41] NOTICE: exiting, bye-bye!
[20-Sep-2013 07:30:09] NOTICE: fpm is running, pid 1905
[20-Sep-2013 07:30:09] NOTICE: ready to handle connections
[20-Sep-2013 07:30:13] WARNING: [pool web1] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 0 idle, and 10 total children
[20-Sep-2013 07:30:14] WARNING: [pool web1] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 16 children, there are 0 idle, and 12 total children
[20-Sep-2013 07:31:10] WARNING: [pool web1] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 0 idle, and 12 total children
[20-Sep-2013 07:31:11] WARNING: [pool web1] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 16 children, there are 0 idle, and 14 total children
[20-Sep-2013 07:31:12] WARNING: [pool web1] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 16 total children
[20-Sep-2013 07:31:13] WARNING: [pool web1] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 18 total children
[20-Sep-2013 07:31:14] WARNING: [pool web1] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 20 total children
[20-Sep-2013 07:32:27] NOTICE: [pool web1] child 2079 exited with code 0 after 73.199058 seconds from start
[20-Sep-2013 07:32:27] NOTICE: [pool web1] child 2099 started
[20-Sep-2013 07:32:29] NOTICE: [pool web1] child 2080 exited with code 0 after 74.523488 seconds from start
[20-Sep-2013 07:32:29] NOTICE: [pool web1] child 2100 started

服务器信息: KVM 客户机 - 带有当前内核的 Centos 6.4 x64。 菲律宾比索 5.4.20 nginx/1.3.14 内存 6GiB

Here is my FPM pool config:
    [web1]
    listen = /var/run/php-fpm/$pool.sock
    user = $pool
    group = $pool
    pm = dynamic
    pm=static
    pm.max_children = 25
    pm.start_servers = 5
    pm.min_spare_servers = 2
    pm.max_spare_servers = 5
    pm.max_requests =  100

    slowlog = /var/log/php-fpm/$pool-slow.log
    php_admin_value[error_log] = /var/log/php-fpm/$pool-error.log
    php_admin_flag[log_errors] = on
    php_admin_value[memory_limit] = 1000M
    php_admin_value[upload_max_filesize] = 2000M
    php_admin_value[post_max_size] = 2000M
    php_admin_value[max_file_uploads] = 1000
    php_admin_value[max_execution_time] = 1200
    php_admin_value[session.gc_maxlifetime] = 86400
    php_admin_value[max_input_time] = 1200
    request_terminate_timeout = 14400s
    rlimit_files = 131072
    chdir = /
    listen.backlog = 16384
    pm.status_path = /status
    env[TMP] =  /var/www/vhosts/$pool/tmp
    env[TMPDIR] = /var/www/vhosts/$pool/tmp
    env[TEMP] =  /var/www/vhosts/$pool/tmp

这是服务器无法处理流量的问题吗?由于服务器提供文件和下载,我的超时时间很长。另外,我不确定这是否是问题所在,因为我以前也见过这种情况,而不会服务器超时。我一直在这里阅读以查找类似的问题/问题,实际上我的 FPM 配置的某些部分取自此处的推荐设置:)

对我的问题的任何见解将不胜感激。

首先,您不能一次设置多个PM设置,您目前有两个。

如果您的情况,我会尝试使用pm = dynamic选项。

然后尝试这些设置,看看是否有帮助:

pm.max_children = 25
pm.start_servers = 5
pm.min_spare_servers = 3
pm.max_spare_servers = 10
pm.max_requests = 0

如果您没有使用任何 CHROOT,请禁用chdir = /

此外,我会非常松散地使用"推荐设置"。与FPM一样,实际上没有"推荐"设置,因为每个服务器规格都会有所不同,每个服务器的负载也会有所不同。

最新更新