一旦池到达pm.max_children,Nginx就会在尝试向PHP-FPM发送新请求时开始超时. @R_301_461@-status页面中的“max listen queue”始终为0.
> @R_301_461@-FPM 5.5.16
> Nginx 1.6.1
以下是@R_301_461@-fpm池的示例:
[example]
catch_workers_output = no
; Configure listener
listen = /var/run/@R_301_461@-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 @R_301_461@ ini settings here
@R_301_461@_admin_flag[log_errors] = on
@R_301_461@_admin_value[open_basedir] = /tmp:/var/www/apc:/var/www/wordpress/example
@R_301_461@_admin_value[error_log] = /var/log/@R_301_461@-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的@R_301_461@-fpm配置中设置的值.这定义了队列长度(reference):
The backlog argument defines the maximum length to which the queue of pending connections
但是,此值受底层系统的限制.看到:
sysctl net.core.somaxconn
据我所知,没有办法将请求排队到上游(@R_301_461@-fpm),如果这会引发错误.但是,如果发生错误,您可以告诉Nginx切换到另一个进程.例如,这可能会触发客户端重新加载.
如果它不是listen-backlog / net.core.somaxconn设置,那么实际问题就是请求阻止@R_301_461@-fpm进程这么久的原因.