Nginx – What’s the Relationship Between an nginx worker_process and PHP-FPM


Me: New to nginx and FastCGI in general, apologies if this is old hat and obvious, but Googling shows me a lot of people recommending random configuration values, but no one that explains the reasoning behind their decisions.

What's the relationship between an nginx worker_process and a PHP-FPM worker? Do more nginx workers means more PHP-FPM workers, or are they unrelated?

My understanding of how this works on a high level is

  1. User requests a web page
  2. nginx handles the request, sees it's a PHP page
  3. nginx hands request off to PHP-FPM
  4. PHP-FPM either handles the request with an existing process, or spawns new ones

What's unclear to me if there's any relationship between PHP-FPM spawning a new child processes, and which nginx worker processes are talking to it. i.e. if you had two identical web server, one with worker_process = 4 and another with worker_process = 8, and they both saw identical web traffic, would one server create more php-fpm child processes than another? Or have I said something so stupid here that it shows I'm missing a fundamental concept? (if so, what?)

Not trying to solve a specific problem — just trying to learn how to reason about the behavior of nginx and php-fpm so I can contribute to scaling and performance brainstorms/troubleshooting.

Best Answer

There is no inherent relation between nginx worker_processes and php-fpm children. They don't even have to be running on the same machine! But if they are on the same machine, they can contend for CPU (which usually isn't a problem as nginx requires very little CPU compared to PHP).