Search code examples
phplinuxubuntuserverproduction

Reloading php-fpm on a production server without affecting current requests


We have a production server with very high specs and to utilize these resources, we want to change the default php-fpm settings like pm.max_children, pm.max_spare_servers, pm.start_servers, and pm.min_spare_servers.

We want to apply this change ASAP, but there are many requests, and we want to make the change without causing a mess.

Can systemctl reload command do this without affecting the current requests? I'm confused about how the reload works actually, will it wait until all the active requests finish? in this case, I think we will wait a long time.

Is it safe to use reload command? Are there rather ways to do this task?

Edit: I don't trust Chat-GPT yet


Solution

  • Based on the man page 'systemctl reload php-fpm' should be what you're looking for :

    reload PATTERN...

    Asks all units listed on the command line to reload their configuration. Note that this will reload the service-specific configuration, not the unit configuration file of systemd. If you want systemd to reload the configuration file of a unit, use the daemon-reload command. In other words: for the example case of Apache, this will reload Apache's httpd.conf in the web server, not the apache.service systemd unit file. This command should not be confused with the daemon-reload command.

    restart PATTERN...

    Stop and then start one or more units specified on the command line. If the units are not running yet, they will be started. Note that restarting a unit with this command does not necessarily flush out all of the unit's resources before it is started again. For example, the per-service file descriptor storage facility (see FileDescriptoreStoreMax= in systemd.service(5)) will remain intact as long as the unit has a job pending, and is only cleared when the unit is fully stopped and no jobs are pending anymore. If it is intended that the file descriptor store is flushed out, too, during a restart operation an explicit systemctl stop command followed by systemctl start should be issued.

    There's also this old post showing that php-fpm supports graceful restart on SysV systems using the reload option.