本文转载自 How To: Solve PHP-FPM server reached max_children | Webcore Community | Webcore Cloud

There are many possible reasons why your PHP-FPM would reach the max_children.
Most common ones are:

  • A lot of concurrent site visitors
  • Slow execution of the PHP scripts due to server resources or buggy scripts
  • Very low setting of max_children setting in php-fpm config

If you have a busy server your php-fpm may crash out with the following error in the logs ( /var/log/phpX-fpm.log or /var/log/plesk-phpXX-fpm/error.log , where X is a PHP version):

tail -f /var/log/php-fpm/error.log

Look for the following entries:

WARNING: [pool example.com] server reached max_children setting (5), consider raising it
ERROR: unable to read what child say: Bad file descriptor (9)

Your website is not accessible with 503 Service Temporarily Unavailable or 502 Bad Gateway error.

Check that php-fpm service is running:

ps aux | grep fpm

Expected output should be running (once):

php-fpm: master process (/opt/plesk/php/5.6/etc/php-fpm.conf)

Check number of allowed running php-fpm processes

ps afvx | grep domain.com
OR: unable to read what child say: Bad file descriptor (9)

Expected output:

7075 pts/0    S+     0:00     19   155 103148  884  0.1          \_ grep domain.com
7018 ?        S      0:02    852  3394 375249 56132  8.3  \_ php-fpm: pool domain.com
7019 ?        S      0:02   1778  3394 374469 55152  8.2  \_ php-fpm: pool domain.com
7021 ?        S      0:01    735  3394 372729 52908  7.9  \_ php-fpm: pool domain.com
7022 ?        S      0:04    716  3394 377661 59236  8.8  \_ php-fpm: pool domain.com

Resolution: Edit the conf file with the following:

vi /etc/php-fpm.conf

or

vi /etc/php-fpm.d/[domain.com].conf

For Plesk follow the instructions on the header of the conf file to override default php-fpm values by creating a custom php.ini file with specific fpm directives in:

/var/www/vhosts/system/mydomain.tld/conf/php.ini

Note that if the file is non-existent and you may need to create it.

Add the following entries:

[php-fpm-pool-settings]
pm = dynamic
pm.max_children = 25
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 20
pm.max_requests = 498

Or for Plesk optionally just add the following entries:

php-fpm-pool-settings]
pm.max_children = 40

Restart php-fpm service:

service php-fpm restart

For Plesk you need to update PHP settings to apply the changes:

/usr/local/psa/bin/php_settings -u

If that fails you can try to recompile domains settings:

/usr/local/psa/admin/sbin/httpdmng --reconfigure-all

or for one domain:

/usr/local/psa/admin/sbin/httpdmng --reconfigure-domain example.com

Then restart php-fpm56 service (or php-fpmXX where X is a PHP version used in Plesk):

service plesk-php56-fpm restart

Verify the max_children limit has increased using the above commands.

If you need to calculate and change these values based on the amount of memory on the system the following command will help us to determine the memory used by each (PHP-FPM) child process:

ps -ylC php-fpm --sort:rss

The RSS column shows non-swapped physical memory usage by PHP-FPM processes in kilo Bytes.
If on an average each PHP-FPM process takes ~85MB of RAM on your server, appropriate value for pm.max_children can be calculated as:

pm.max_children = Total RAM dedicated to the web server / Max child process size

The server has 8GB of RAM, so:

pm.max_children = 6144MB / 85MB = 72

You need to take into account any other services running on the machine while calculating memory usage.
Then change the settings as follow:

pm.max_children = 70
pm.start_servers = 20
pm.min_spare_servers = 20
pm.max_spare_servers = 35
pm.max_requests = 500

You can check an average memory usage by single PHP-FPM process with this handy command: 检测PHP-FPM平均占用内存脚本

ps --no-headers -o "rss,cmd" -C php-fpm | awk '{ sum+=$1 } END { printf ("%d%s\n", sum/NR/1024,"M") }'

You can use the same steps above to calculate the value for MaxClients for Apache web server - just substitute the php-fpm with httpd.

如何解决PHP-FPM报错: server reached max_children相关推荐

  1. 关于eclipse中web项目tomcat报错Server Tomcat v9.0 Server at localhost failed to start问题解决

    第一次写博客,写个简单的好了 关于eclipse中web项目tomcat报错Server Tomcat v9.0 Server at localhost failed to start 问题 我的解决 ...

  2. 解决IntelliJ IDEA报错:调用方法[manageApp]时发生异常java.lang.IllegalStateException: 启动子级时出错

    解决IntelliJ IDEA报错:调用方法[manageApp]时发生异常java.lang.IllegalStateException: 启动子级时出错 问题描述:   笔者将一个在 Tomcat ...

  3. ntpdate解决同步时间报错 the NTP socket is in use, exiting

    ntpdate解决同步时间报错 the NTP socket is in use, exiting  在HBase启动服务前首先查看集群时间是否同步 <第一步> 检查是否安装ntpd,nt ...

  4. IDEA 配置连接数据库报错 Server returns invalid timezone. Need to set ‘serverTimezone‘ property.

    项目场景: 提示:使用IDEA连接数据库: 问题描述 提示:IDEA 配置连接数据库报错 Server returns invalid timezone. Need to set 'serverTim ...

  5. mysql5.7 1045 pc,解决MySQL5.7报错ERROR 1045 (28000): Access denied for user

    解决MySQL5.7报错ERROR 1045 (28000): Access denied for user 解决MySQL5.7报错ERROR 1045 (28000): Access denied ...

  6. Eclipse中更改JDK版本,解决ant编译报错的问题

    要改一个JDK版本 主要是为了解决ant编译报错,JDK版本不一致的问题. 1. Windows--Preferences--Java--Compiler(配置的为1.8)--Installed JR ...

  7. 解决fitz模块报错

    解决fitz模块报错 使用Python处理PDF文档时,需要使用fitz模块.由于Python 3.8与fitz有兼容问题,会出现以下错误信息: [省略部分错误信息] RuntimeError: Di ...

  8. 解决MySQL8.0报错:Unknown system variable 'validate_password_policy'

    解决MySQL8.0报错:Unknown system variable 'validate_password_policy'   一.问题描述 1.在安装MySQL8.0时,修改临时密码,因密码过于 ...

  9. 成功解决调用密钥报错4001 加密方式错误

    成功解决调用密钥报错4001 加密方式错误 目录 解决问题 解决思路 解决方法 解决问题 成功解决调用密钥报错4001 加密方式错误 解决思路 秘钥没有打开,会出现这样的错误! 解决方法 关掉密钥按钮 ...

最新文章

  1. 框架模式与设计模式之区别
  2. CentOS 7下编译安装Open Babel2.4.1和python绑定
  3. RAM测试方法 C语言实现,有哪些常用单片机系统RAM测试方法?基于种子和逐位倒转的RAM故障测试法有什么优点?...
  4. 执行python时,ImportError: No module named xxx的解决方法
  5. 如何使用Mybatis-plus
  6. numpy将bool值转换成数值
  7. http协议知识msdn
  8. python函数手册中文_Python中文手册-Python函数
  9. 数据处理——数据编码
  10. 操作系统—进程的状态与状态的转换
  11. 数组模拟栈解决括号匹配
  12. 计算机1级题库软件,计算机一级软件哪个好_计算机一级刷题软件_计算机一级试题软件...
  13. 如何安装biopython_Biopython - 安装
  14. p9plus升级鸿蒙,华为P9 Plus(VIE-AL10 EMUI 8.0)手机完美获取root教程,最强root工具,亲测可用!...
  15. Word——从任意页开始设置页码的方法
  16. 【usb】USB Core功能解析(一)-------linux那些事儿之我是usb
  17. Altium designer18系列教程一 建工程和封装介绍
  18. python双层for循环控制图像逐行扫描和逐列扫描
  19. 集成学习研究现状及展望
  20. 16进制与10进制转换(Qt)

热门文章

  1. [翻译] Overleaf 常见错误
  2. HBase部署之官网翻译
  3. 计算机互联网行业和地产行业哪个好,互联网行业毕业生起薪最高 互联网、金融、房地产人才很紧缺...
  4. Oracle 11g数据库基础教程(第2版)-课后习题-第十四章
  5. Bootloader详解,理解Bootloader看这篇就够了
  6. Gogs集成LDAP
  7. WDL - 添加变量(二)
  8. git忽略本地已存在文件的修改
  9. 软硬链接 文件查找(find)
  10. 查看本机 ssh 公钥,生成公钥