PHP processes & children

Hi there

Not strictly an nginx question but don’t know where else to ask and I
think some of you will have valuable opinions on this!

nginx <-- fastcgi --> php

Is it better to have 1 PHP master process on 1 port re-spawning many
children, or many PHP masters on many ports spawning fewer children?

E.g. one master with e.g. 32 worker children on 1 port, or 4 masters
with 8 children each on 4 ports?

Initial thoughts would be more masters as it’s a multi-core box, but
not sure, if all cores are switching and respawning could that get

Many thanks for any input …

From PHP performance perspective, one master with 32 children will do
because they will share more memory pages and have slightly smaller
footprint. Besides, the master process doesn’t do anything other than
re-spawning dead children, which is a rare event.

There is one case when you might want multiple master processes, though.
If your server handles multiple sites with different databases, you may
to separate them on one php pool per database basis. The reason is that
databases queries can stall until another query terminates (particularly
MySQL with MyISAM tables). So, if the query takes significant time
to the request rate, the whole php pool will get stuck waiting for the
database. If your other sites are handled by other php pools they’ll
little to no impact, otherwise they’ll stall as well.

Thanks very much Denis, excellent stuff.

best wishes