6

I set up my nginx with php-fpm. Each vhost has its own unix-socket and separate POOL.
But the problem is that php-fpm is creating 7 thread for each config pool that I created in /etc/php5/fpm/pool.d/

Why? And how could I define that the pool creates only when the url related to VHOST is viewed.

enter image description here

sotirov
  • 4,379
r004
  • 173

2 Answers2

10

The number of children is controlled by the process manager configuration directives in the pool configuration file. I guess the current settings are either pm = static with pm.max_children = 6 or pm = dynamic with pm.start_servers = 6. One process would be the controlling process, the others would be children ready to handle requests. If you only have 5 not 6 children configured, then I must confess I don't know what that last process is used for. On large high-throughput sites, such a configuration with many ready-to-use children makes sense, but in a memory-constrained (probably virtual) environment where you only expects PHP scripts to execute every now and then, a different configuration might be more appropriate.

To achieve this, edit the pool config files and set pm = ondemand. Then children will be created only to handle requests. This will mean less memory consumption while no requests are active, although it might also mean more time required to create a child. The latter can be reduced by choosing a reasonable pm.process_idle_timeout, so that a sane number of php processes remain idle while users can be expected to use them again soon. That “sane number” is controlled by pm.max_children.

Note: This advice is based on my experience with Debian 7, but it should apply to Ubuntu as well.

MvG
  • 1,536
1

Lots of people encourage to use pm=ondemand to save memory. However, it also means that your time to first byte (or server answer ) is going to be very big because if your web server had no recent visits, the php-fpm module will have to first create a child before answering a request. If you use pm=dynamic, it means you will always have at least 1 child ready to answer a client request. The following will load 1 child per user after restarting php-fpm:

pm=dynamic
pm.start_servers=1
pm.min_spare_servers=1
sotirov
  • 4,379