加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

在使用Nginx和PHP-FPM的pm.max_children之后,请求永远不会排队

发布时间:2020-12-13 21:19:09 所属栏目:Nginx 来源:网络整理
导读:一旦池到达pm.max_children,Nginx就会在尝试向PHP-FPM发送新请求时开始超时. php-status页面中的“max listen queue”始终为0. PHP-FPM 5.5.16 Nginx 1.6.1 以下是php-fpm池的示例: [example]catch_workers_output = no; Configure listenerlisten = /var/r

一旦池到达pm.max_children,Nginx就会在尝试向PHP-FPM发送新请求时开始超时. php-status页面中的“max listen queue”始终为0.

> PHP-FPM 5.5.16
> Nginx 1.6.1

以下是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”的预期行为:

The 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进程这么久的原因.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读