Nic*_*ick 4 nginx php-fpm ubuntu-16.04
该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
Run Code Online (Sandbox Code Playgroud)
设置来自/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
Run Code Online (Sandbox Code Playgroud)
设置来自/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
Run Code Online (Sandbox Code Playgroud)
所有其他行都用;(默认设置)注释掉。这是 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)
Run Code Online (Sandbox Code Playgroud)
未进行任何调整(除了启用日志记录)。此服务器尚未部署到生产环境,因此没有用户负载。
为什么 php-fpm 每秒生成并立即摧毁数百个孩子?这是配置错误,还是 Ubuntu 16.04 附带有错误的 php-fpm 版本?
小智 6
既不是配置错误也不是错误版本。事实上,没有什么可担心的。
您的进程退出和重新生成如此之快的原因是您pm.max_requests在 php-fpm 池配置文件中使用了默认值,因为它通过分号;符号进行了注释。要了解什么pm.max_requests参数代表,您可以阅读以下取自默认配置的说明:
pm.max_requests = int
每个子进程在重生之前应该执行的请求数。这对于解决 3rd 方库中的内存泄漏很有用。对于无休止的请求处理,请指定“0”。相当于 PHP_FCGI_MAX_REQUESTS。默认值:0。
你是 0 ,因为它被评论了。您可以将其设置为 100-500(取决于您的需要),以便您的 php-fpm 在处理该数量的请求后回收该进程。
顺便说一下,您应该注意日志文件中的这些消息只是信息性的,没有任何问题,所以不用担心。可以通过使用 的值warning代替 中notice的log_level参数来避免这些日志条目php-fpm.conf。它几乎显示了所有内容 - 略低于debug级别 - 因为默认值设置为notice.
取自默认配置:
log_level = 字符串
错误日志级别。可能的值:警报、错误、警告、通知、调试。默认值:通知。
祝你好运
| 归档时间: |
|
| 查看次数: |
5744 次 |
| 最近记录: |