简体   繁体   中英

php-fpm and dns not work well randomly

Sometimes I got error message:

stream_socket_client(): php_network_getaddresses: getaddrinfo failed: Name or service not known

I found that problem is always with php-fpm, because after restarting php-fpm service its working well again. Its happen randomly on 1-3 month periods. Or it will happen when name resolve functions are used many times in one php session. My server is CentOS 7.5, Apache 2.4, PHP 7.x, updated. Do you know what problem should be?

In log I see only some:

WARNING:server reached pm.max_children setting (8), consider raising it

but it workx normal.

Most common ones why PHP-FPM would reach the max_children are:

  • A lot of parallel requests from your clients
  • Very low setting of the max_children

But, for this case I assume that caused by low setting of max_children. So please increase it.

$ sudo vi /etc/php-fpm.d/www.conf

You can find pm.max_children under [php-fpm-pool-settings] section.

To get an idea of what to use for the pm.max_children , you can use this calculation:

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

Remember to leave some RAM for extra services you have running on your system.

Also remember, higher isn't always better. If you have a bad PHP script, these settings won't resolve your issues. Tweak these settings and see what works best on your server. After you make the changes, you need to restart your PHP-FPM service.

$ sudo systemctl restart php-fpm

Please check this tutorial for more information

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM