PHP7.0-fpm.log显示每秒产生数百个孩子,然后被立即销毁.这种情况不停发生.日志看起来像这样:
[09-Mar-2017 02:58:25] NOTICE: [pool www] child 4980 started
[09-Mar-2017 02:58:25] NOTICE: [pool www] child 4978 exited with code 0 after 0.014658 seconds from start
[09-Mar-2017 02:58:25] NOTICE: [pool www] child 4981 started
[09-Mar-2017 02:58:25] NOTICE: [pool www] child 4980 exited with code 0 after 0.014354 seconds from start
[09-Mar-2017 02:58:25] NOTICE: [pool www] child 4982 started
[09-Mar-2017 02:58:25] NOTICE: [pool www] child 4979 exited with code 0 after 0.015170 seconds from start
[09-Mar-2017 02:58:25] NOTICE: [pool www] child 4983 started
[09-Mar-2017 02:58:25] NOTICE: [pool www] child 4981 exited with code 0 after 0.014709 seconds from start
[09-Mar-2017 02:58:25] NOTICE: [pool www] child 4984 started
[09-Mar-2017 02:58:25] NOTICE: [pool www] child 4982 exited with code 0 after 0.014741 seconds from start
[09-Mar-2017 02:58:25] NOTICE: [pool www] child 4985 started
[09-Mar-2017 02:58:25] NOTICE: [pool www] child 4983 exited with code 0 after 0.014727 seconds from start
[09-Mar-2017 02:58:25] NOTICE: [pool www] child 4986 started
/etc/PHP/7.0/fpm/PHP-fpm.conf中的设置:
pid = /run/PHP/PHP7.0-fpm.pid
error_log = /var/log/PHP7.0-fpm.log
include=/etc/PHP/7.0/fpm/pool.d/*.conf
/etc/PHP/7.0/fpm/pool.d/www.conf中的设置:
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
;pm.process_idle_timeout = 10s;
;pm.max_requests = 500
catch_workers_output = yes
PHP_flag[display_errors] = on
PHP_admin_value[error_log] = /var/log/PHPerrors.log
PHP_admin_flag[log_errors] = on
所有其他行都注释掉了; (默认设置).这是Ubuntu 16.04,使用默认包. PHP和Nginx版本如下:
PHP-fpm7.0 -v
PHP 7.0.13-0ubuntu0.16.04.1 (fpm-fcgi)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0,Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.13-0ubuntu0.16.04.1,Copyright (c) 1999-2016,by Zend Technologies
Nginx -v
Nginx version: Nginx/1.10.0 (Ubuntu)
没有进行调整(除了启用日志记录).此服务器尚未部署到生产环境,因此没有用户负载.
为什么PHP-fpm产生并立即每秒摧毁数百名儿童?这是一个配置错误,还是Ubuntu 16.04附带了一个错误的PHP-fpm版本?
您的进程退出并快速重新生成的原因是您在PHP-fpm池配置文件中使用pm.max_requests的默认值,因为它是通过分号进行注释的;符号.要了解pm.max_requests参数的含义,您可以阅读以下默认配置中的描述:
pm.max_requests = int
The number of requests each child process should
execute before respawning. This can be useful to work around memory
leaks in 3rd party libraries. For endless request processing specify
‘0’. Equivalent to PHP_FCGI_MAX_REQUESTS. Default value: 0.
你的评论是你自己的0.您可以将其设置为100-500(根据您的需要),以便在处理了大量请求后让您的PHP-fpm回收流程.
顺便说一下,你应该注意到你的日志文件中的这些消息只是信息性的而且没有任何错误,所以你不用担心.通过使用PHP-fpm.conf中log_level参数的warning而不是notice的值,可以避免这些日志条目.它几乎显示了所有内容 – 比调试级别略低 – 因为默认值设置为通知.
取自默认配置:
log_level = string
Error log level. Possible values: alert,error,
warning,notice,debug. Default value: notice.
祝好运