Follow-up: use ondemand PHP-FPM masters using systemd

A few days ago, I published a blogpost called A better way to run PHP-FPM . It’s gotten a fair amount of attention. It detailed the use of the “ondemand” process manager as well as using a separate PHP-FPM master per pool, for a unique APC cache.

The setup works fine, but has the downside that you’ll have multiple masters running – an obvious consequence. Kim Ausloos created a solution for this by using systemd’s socket activation (the original write-up at thanatos.be has since gone offline). This means PHP-FPM masters are only started when needed and no longer stay active on the system when obsolete. If you want to set this up today, see the systemd.socket documentation on socket activation.

This has a few benefits and possible downsides;

  • Pro: masters are only spawned when needed, meaning less memory consumed overall
  • Pro: masters are also killed when they’re obsolete, so a perfect ondemand scenario
  • Min: no longer able to restart a PHP-FPM pool when needed (to load new .INI settings), all pools would restart?
  • Min: APC cache will be destroyed whenever a PHP-FPM master is killed (which may not be a bad thing, for low-traffic sites)

I’ll do some more testing on this use-case, as well as the performance penalty (if any) of having to start new master on a first request to the PHP-FPM socket. For this to work out, RHEL or CentOS 7 is needed in my case (we ’re a RHEL/CentOS shop), as systemd is required and will only be supported from RHEL/CentOS 7.