As I posted before, I have been using PHP-FPM for many years. I added a PHP-FPM status page recently.

Now I am using PHP8.2, so I may use PHP-FPM or PHP8.2-FPM to mention it.

About the PHP-FPM, I am always using its default configuration.

Today, I studied a post on Tideways. It talked about the three different process manager configurations, their related settings, and discussed when each configuration makes sense.  I tried to understand it and updated my PHP8.2-FPM settings according to its guide.

The PHP8.2-FPM settings are in the file /etc/php/8.2/fpm/pool.d/www.conf

I looked at the file. My current settings are as below:

pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
;pm.process_idle_timeout = 10s

I am using the formula to get the figure.

max_children (Total RAM – Memory used for Linux, DB, etc.) / process size
start_servers Number of CPU cores x 4
min_spare_servers Number of CPU cores x 2
max_spare_servers Same as start_servers

The first number I need number of CPU cores. My VPS has 4 cores.

The second is total RAM of my VPS. It is 8GB. I assumed the memory used for Ubuntu, MySQL server, etc. is 2GB.

I also need a process size of PHP8.2-FPM.

So I got the file. Then run it with sudo python3 | grep php-fpm

8.3 MiB + 9.6 MiB = 17.9 MiB php-fpm8.0 (3)
8.5 MiB + 10.4 MiB = 18.9 MiB php-fpm8.3 (3)
9.1 MiB + 13.0 MiB = 22.1 MiB php-fpm8.1 (6)
102.1 MiB + 145.7 MiB = 247.8 MiB php-fpm8.2 (9)

Here, the last line is PHP8.2-FPM. The memory each process needs is 248MB.

I got my new figure.

pm = dynamic
pm.max_children = 24
pm.start_servers = 16
pm.min_spare_servers = 8
pm.max_spare_servers = 16
;pm.process_idle_timeout = 10s

I gave it a little bit of room for other programs, I may need on this VPS.

pm = dynamic
pm.max_children = 20
pm.start_servers = 8
pm.min_spare_servers = 4
pm.max_spare_servers = 8
pm.process_idle_timeout = 10s

And I remove the comment sign from the timeout setting as well.

Save the settings and restart the PHP-FPM by running sudo service php8.2-fpm restart

Now I check the status of PHP-FPM.



David Yin

David is a blogger, geek, and web developer — founder of If you like his post, you can say thank you here

One Reply to “How to Optimize PHP-FPM”

  1. According to the config file: “pm.process_idle_timeout Note: Used only when pm is set to ‘ondemand”

Leave a Reply

Your email address will not be published. Required fields are marked *