hollodotme/fast-cgi-client
High-performance FastCGI client for PHP that talks directly to PHP-FPM (no web server needed). Send requests, set env vars and stdin, read stdout/stderr, and run scripts in parallel—useful for CLIs, workers, or custom application servers.
Start by installing the package via Composer: composer require hollodotme/fast-cgi-client. The main entry point is the FastCgi\Client class — instantiate it with a connector (e.g., TcpSocketConnector or UnixSocketConnector) pointing to your FastCGI backend (e.g., 127.0.0.1:9000 for PHP-FPM or /run/php/php-fpm.sock). To execute a PHP script, prepare a Request with the script path, query string (optional), and custom params (e.g., $_SERVER variables). Then call execute() and read the response using getStdout() or getStderr(). A minimal first use case is running a PHP snippet directly against FPM without Apache/Nginx:
$connector = new \FastCgi\Connectors\UnixSocket('/run/php/php-fpm.sock');
$client = new \FastCgi\Client($connector);
$request = new \FastCgi\Request('/path/to/script.php', [], ['SCRIPT_FILENAME' => '/path/to/script.php']);
$response = $client->execute($request);
echo $response->getStdout();
Check the examples/ directory in the repo for quick start patterns.
Request to configure behavior.<?php echo 'ok'; snippet.$_SERVER and $_ENV, avoiding fixture dependencies on web servers.setParams() to inject arbitrary FastCGI params (e.g., PHP_VALUE, PHP_ADMIN_VALUE) for runtime configuration overrides without .ini changes.Client instance (thread-safe) for multiple requests to reduce socket overhead — especially beneficial under load.SCRIPT_FILENAME must be resolvable by the FPM process — misconfigurations (e.g., mismatched paths between client/server) yield 404 or 500 silently. Enable debug logging via Request::setVerbose(true) or inspect $response->getRawRecords().FCGI_VERSION_1, which is standard, but older FPM versions may need manual tuning.stderr, but FPM often logs errors internally instead. Always inspect raw records ($response->getStderr() + protocol-level FCGI_STDERR blocks) for debugging.pcntl_async_signals() or reactive loops (e.g., ReactPHP via reactphp/socket) for non-blocking usage.try/catch — TimeoutException may be thrown; configure timeouts via connector: (new UnixSocket($path))->setTimeout(3.0).StreamSelectLoop (see examples in repo).clear_env = no in php-fpm.conf if expecting to pass arbitrary $_SERVER values — otherwise, FPM may discard custom params.How can I help you explore Laravel packages today?