一旦池到达pm.max_children,Nginx就会在尝试向PHP-FPM发送新请求时开始超时. PHP-status页面中的“max listen queue”始终为0.
以下是PHP-fpm池的示例:
[example]
catch_workers_output = no
; Configure listener
listen = /var/run/PHP-fpm/example.sock
listen.backlog = 65535
listen.owner = Nginx
listen.group = Nginx
; Unix user/group of processes
user = Nginx
group = Nginx
; Choose how the process manager will control the number of child processes.
pm = ondemand
pm.max_children = 10
pm.max_requests = 200
pm.process_idle_timeout = 30s
pm.status_path = /status
; Pass environment variables
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
; Host specific PHP ini settings here
PHP_admin_flag[log_errors] = on
PHP_admin_value[open_basedir] = /tmp:/var/www/apc:/var/www/wordpress/example
PHP_admin_value[error_log] = /var/log/PHP-fpm/example.log
最佳答案
由于这个问题仍然存在于未解答的问题中,我将尝试一个过时的答案.根据PHP manual,显示错误是设置“pm.max_children”的预期行为:
原文链接:https://www.f2er.com/nginx/435458.htmlThe number of child processes … to be created when pm is set to dynamic.
This option sets the limit on the number of simultaneous requests that will be served.
但是,每个请求都应该很快处理,因此下一个请求的过程是免费的.如果没有,Nginx可能会在无法处理更多请求时立即报告“502 Bad Gateway”.
仔细检查listen.backlog的PHP-fpm配置中设置的值.这定义了队列长度(reference):
The backlog argument defines the maximum length to which the queue of pending connections
但是,此值受底层系统的限制.看到:
sysctl net.core.somaxconn
据我所知,没有办法将请求排队到上游(PHP-fpm),如果这会引发错误.但是,如果发生错误,您可以告诉Nginx切换到另一个进程.例如,这可能会触发客户端重新加载.
如果它不是listen-backlog / net.core.somaxconn设置,那么实际问题就是请求阻止PHP-fpm进程这么久的原因.