# PHP-FPM can't start more than two pools



## huehnerhose (Dec 13, 2014)

Hi,

I have the strange problem that I can't start more than two php-fpm pools. I want to host multiple websites on my server and thought it would be a good idea to give every website/user it's own php-fpm pool (nginx, php-fpm).

My /usr/local/etc/php-fpm.conf simply includes alle *.pool files and every pool got its own listen port (9000,9001,9002,...).

Starting php-fpm works perfectly, pool-files get included and php-fpm.log (debug) also shows:

```
[13-Dec-2014 09:18:09.641808] DEBUG: pid 23693, fpm_children_make(), line 421: [pool talontr] child 23694 started
[13-Dec-2014 09:18:09.642977] DEBUG: pid 23693, fpm_children_make(), line 421: [pool talontr] child 23695 started
[13-Dec-2014 09:18:09.644128] DEBUG: pid 23693, fpm_children_make(), line 421: [pool trollreport] child 23696 started
[13-Dec-2014 09:18:09.648186] DEBUG: pid 23693, fpm_children_make(), line 421: [pool trollreport] child 23697 started
[13-Dec-2014 09:18:09.649804] DEBUG: pid 23693, fpm_children_make(), line 421: [pool zzz] child 23698 started
[13-Dec-2014 09:18:09.650866] DEBUG: pid 23693, fpm_children_make(), line 421: [pool zzz] child 23699 started
[13-Dec-2014 09:18:09.652521] DEBUG: pid 23693, fpm_children_make(), line 421: [pool huehnerhose] child 23700 started
[13-Dec-2014 09:18:09.654318] DEBUG: pid 23693, fpm_children_make(), line 421: [pool huehnerhose] child 23701 started
```

But `netstat -a` shows only two ports, the pools aren't reachable
	
	



```
tcp4       0      0 10.0.0.10.9002         *.*                    LISTEN
tcp4       0      0 10.0.0.10.9001         *.*                    LISTEN
```
Now I tried to deactivate one pool-file after another. Whatever pool files are active: if more than two are present only the ones with 9002 and 9001 are active. If only two pool-definitions are present whatever port is defined gets startetd correctly.

I really don't have any explanation or idea where to start debugging this, grateful for any advise

Edit:
php-fpm and nginx are running inside a jail. I am relatively new to FreeBSD and the concept of jails, so I don't know if there could be a hidden error source somwhere.


----------



## storvi_net (Dec 13, 2014)

Do you use the same jail for nginx and php-fpm or separate jails?


----------



## huehnerhose (Dec 13, 2014)

I use the same jail.


----------



## storvi_net (Dec 13, 2014)

So why don't you use sockets?
php-fpm.conf

```
; Include vhosts
include=/usr/local/etc/php/*.conf
```
In each configuration file
	
	



```
[poolname]
; This file is included into every .confo
listen = /var/run/php-$pool.sock
```
Then in the per-vhost configuration in nginx

```
# PHP
  location ~ \.php$ {
  fastcgi_pass unix:/var/run/php-poolname.sock;
  fastcgi_index index.php;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  include fastcgi_params;
```

Regards
Markus


----------



## huehnerhose (Dec 14, 2014)

Fair point, this works. But it doesn't feel like a win 

Seriously: I can live with that, for now. But I am really interested why there was this strange behavior in the first place.

Thanks!


----------



## MattH (Dec 18, 2014)

I am having the same problem on 10.1 and 10.0 with both php55 and php56. First 2 pools are only created, none of the others. Sockets are not a solution on our load balanced multi server setup. Glad to hear someone else had the problem. 

It looks like php-5.4.35 from the ports does not have this problem...


----------



## MattH (Dec 19, 2014)

I narrowed it down to sapi/fpm/fpm/fpm_sockets.c and sapi/fpm/fpm/fpm_sockets.h. If I pull those in to 5.6 from 5.4, it at least opens all the ports.

Narrowing down a bit more, if I reverse the ipv6 patch - https://github.com/php/php-src/commit/15ba757a2b7c6810bc23ac9e158a7b901232b2aa, it opens the ports.


----------



## huehnerhose (Dec 19, 2014)

big thanks to you  MattH
Then this looks like an PHP bug? But why does it seem like we are the only one experience this error. Is a setup with multiple php-fpm pools so rare or is there some interaction with FreeBSD?
I think the php bugtracker will love your post  I'm really looking forward to get rid of these socket files


----------



## xtaz (Dec 19, 2014)

Why would you want to get rid of the socket files? My understanding is that sockets would be faster because you don't have the overhead of the TCP/IP protocol to care about.


----------



## MattH (Dec 19, 2014)

xtaz said:


> Why would you want to get rid of the socket files? My understanding is that sockets would be faster because you don't have the overhead of the TCP/IP protocol to care about.



The problem with socket files is that they only work in the same jail/machine. Although there is some performance penalty, using TCP ports allows for complete separation of the PHP process from the webserver or every other PHP process. From just a management view, I can keep PHP and the many many many dependencies isolated and even run multiple PHP versions, multiple hosts/jails to scale, etc...

I will post a bug report to PHP and see what they say. I have a feeling it is specific to FreeBSD.


----------



## MattH (Dec 19, 2014)

This patch seems to fix the problem https://github.com/php/php-src/commit/23db11976889c3600cf7853fe0fd687a1c9435e6.patch and the 5.6.4 release (yesterday) should have this included.


----------

