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 ps_mem.py file. Then run it with sudo python3 ps_mem.py | 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.