phpfpm
phpfpm
phpfpm
A Go library for talking to PHP-FPM. It discovers running masters, parses their effective configuration, scrapes live status over FastCGI, validates a configuration, and reloads a master without dropping a request.
It is the shared layer beneath fpm-exporter, which reads a host, and fpm-tune, which reads and writes one. Neither depends on the other; both depend on this.
go get github.com/cboxdk/phpfpm
The mental model
The library is a set of standalone functions over a few small value types. There
is no client to construct and no connection to hold open — you call Discover,
Scrape, Validate or ReloadAndWait when you need an answer, and pass a
*slog.Logger to the ones that can log.
Two ideas run through all of it:
- A pid is a promise about the instant it was read. A master can exit between discovery and a reload, and the kernel can reuse the number — so anything that signals a process verifies its identity first, and confirms the master rather than the number afterwards. See Identity and trust.
- The process table is not a trust boundary. Any local user can start a
process that looks like php-fpm and names a config they control, and both are
handed to
exec— so discovery checks ownership and refuses paths it should not run. See Identity and trust.
The surface
| Task | Entry point |
|---|---|
| Find masters and their pools | Discover |
| Find masters only | DiscoverMasters |
| Parse effective configuration | ParseConfig, ParseConfigContext |
| Scrape live status | Scrape, ScrapeAll |
| Read opcache | GetOpcacheStatus |
| Validate a configuration | Validate |
| Reload a master | ReloadAndWait, ReloadMaster |
| Confirm a master's identity | VerifyMaster, MasterPID |
| Invalidate the parse cache | InvalidateConfigCache |
Full reference: pkg.go.dev/github.com/cboxdk/phpfpm.