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

Want to help support this blog? Try out Oh Dear, the best all-in-one monitoring tool for your entire website, co-founded by me (the guy that wrote this blogpost). Start with a 10-day trial, no strings attached.

We offer uptime monitoring, SSL checks, broken links checking, performance & cronjob monitoring, branded status pages & so much more. Try us out today!

Profile image of Mattias Geniar

Mattias Geniar, April 13, 2014

Follow me on Twitter as @mattiasgeniar

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. This means PHP-FPM masters are only started when needed and no longer stay active on the system when obsolete.

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.



Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.