Servers Softwares Uncategorized

PHP 8.2 FPM Tuning

This is a personal note for myself to remember the process I used to tune the php-8.2-fpm service on this computer running this website.

This site is running on a re-purposed laptop to work as a home server since running this website on a shared hosting has become erratic due to increasing traffic on the website – 6yrs and 297 days running now since I started the website (as of this writing). The shared hosting account that previously runs this website is running out of memory resources due to occasional spike in traffic. I also cannot run this website together with its database on a single computer since it is overloading the laptop a Core 2 Dou computer with 3GB of RAM.

So to make this website run on this computer since hosting it on a VPS server is a little bit expensive for me at the moment. I decided to use my home fiber bandwidth which is I think would be enough to run this website for the occasional spike in traffic. I configured this website on top of Apache2 / PHP-FPM / opcache and Redis server and separate the MySQL database to run on another netbook Atom processor with 2GB ram running on SSD.

The issues that I need to resolve is to prevent the PHP-FPM process to take all the memory resources upon computer start up. So I need to calculate properly the PHP consumption being used by PHP-FPM.

To check I execute this command:

$ ps -C php-fpm8.2 -o rss=

Ignoring the first line on the output I noticed that PHP is using around 75Mb of memory. So to configure I will allocate 2GB of RAM for PHP and configure the php-fpm service to run with dynamic allocation.

So 2000MB / 75MB = 30.769

Therefore I will set the pm.max_children to 30, and will set additional parameters accordingly.

pm.max_children = max_children

pm.start_servers = 25% of max_children

pm.min_spare_servers = 25% of max_children

pm.max_spare_servers = 75% of max_children

Applying the resulting calculations this is now my php-fpm configuration

pm = dynamic
pm.max_children = 30
pm.start_servers = 8
pm.min_spare_servers= 8
pm.max_spare+servers= 23

Save the configuration in my php-fpm configuration file, restart the server and voila. No startup freeze and php-fpm process hugging up the memory resources.