fcgx
Minimal, robust FastCGI client library for Go. Context and timeout support, structured error handling, designed for PHP-FPM integration.
fcgx is a minimal FastCGI client library for Go. It implements the FastCGI protocol with first-class context support, structured error handling, and thread safety. It is the protocol layer that powers FPM Exporter.
Why another FastCGI library?
Context Support
Every request accepts a context.Context for timeouts and cancellation. No more hanging connections to unresponsive PHP-FPM pools.
Structured Errors
Sentinel errors (ErrClientClosed, ErrTimeout, ErrConnRefused) that you can check with errors.Is() instead of parsing error strings.
Thread Safety
Fully safe for concurrent use. Run requests from multiple goroutines against the same client without synchronization.
Unix + TCP
Connect via Unix sockets (/var/run/php-fpm.sock) or TCP (127.0.0.1:9000). Automatic detection and connection handling.
Built for monitoring
Most FastCGI libraries are built for proxying HTTP requests. fcgx is built for monitoring. It is optimized for the pattern of sending a small request, reading a small response, and doing it thousands of times per minute with strict timeouts. Connection pooling, automatic reconnection, and context-aware cancellation make it reliable in production monitoring loops.
Installation
go get github.com/cboxdk/fcgx