To set up PHP-FPM process manager options for better performance, you can follow these steps:
Find the PHP-FPM configuration file: This can usually be found at /etc/php/{version}/fpm/pool.d/www.conf
.
Open the configuration file in a text editor.
Adjust the following options:
pm
: This option determines the process manager to be used in PHP-FPM. The most commonly used options are:
static
: Fixed number of child processes.ondemand
: Child processes are created on-demand as needed.dynamic
: Dynamic number of child processes based on the server's workload.Choose the appropriate option based on your server's requirements. If you have a lot of traffic, dynamic
or ondemand
may be more suitable.
pm.max_children
: This option sets the maximum number of child processes. Increase this value if you have a lot of traffic. Remember to consider your server resources when determining this value.
pm.start_servers
, pm.min_spare_servers
, pm.max_spare_servers
: These options control the number of child processes that should be started, the minimum number of spare processes, and the maximum number of spare processes, respectively. Adjust these values based on your server's traffic and resource availability.
pm.max_requests
: This option sets the maximum number of requests a child process should handle before it is terminated. Restarting child processes periodically can help improve memory usage and prevent memory leaks. Set a value appropriate for your application.
Save the changes to the configuration file.
Restart PHP-FPM service: Use the appropriate command for your system. For example, on Ubuntu, you can use sudo service php{version}-fpm restart
.
By optimizing the PHP-FPM process manager options, you can ensure that PHP-FPM is utilizing the server resources efficiently, resulting in better performance for your PHP applications.