PHP-FPM和超时(503)

时间:2013-09-20 08:10:18

标签: nginx lamp php

我的服务器运行Nginx + PHP-FPM设置时遇到了一些问题。本周我们的用户在CEST 02.00左右后看到了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与当前内核。     PHP 5.4.20     nginx的/ 1.3.14     RAM 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配置的某些部分来自这里推荐的设置:)

非常感谢对我的问题的任何见解。

1 个答案:

答案 0 :(得分:0)

首先,您不能同时设置多个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一样,实际上没有“推荐”设置,因为每个服务器规范都会有所不同,每台服务器的负载也会不同。