Skip to main content

FastCGI Client

Send requests (a)synchronously to PHP-FPM using the FastCGI protocol

composer require hollodotme/fast-cgi-client

Execute PHP scripts through PHP-FPM, from PHP

The FastCGI Client speaks the FastCGI protocol directly to PHP-FPM or any other FastCGI server. Use it to run background jobs in parallel worker processes, to warm up caches, or to call scripts on another host — without a web server in between.

use hollodotme\FastCGI\Client;
use hollodotme\FastCGI\Requests\GetRequest;
use hollodotme\FastCGI\SocketConnections\NetworkSocket;

$client = new Client();
$connection = new NetworkSocket( '127.0.0.1', 9000 );
$request = new GetRequest( '/path/to/script.php' );

echo $client->sendRequest( $connection, $request )->getBody();

Sync and async

Send a request and wait for the response, or fire many requests in parallel and read the responses in order or as soon as they are ready.

Network and unix domain sockets

Talk to PHP-FPM over TCP or a local socket file, with configurable connect and read/write timeouts.

Callbacks and streaming

Notify callbacks on responses and failures, and stream the output of long-running scripts while they are still running.

All kinds of request content

GET, POST, PUT, PATCH and DELETE requests with URL-encoded, multipart (file upload), JSON or plain text content.

Strict protocol handling

Validates every received record and splits oversized content into FastCGI records, as the specification demands.

Proven compatibility

No dependencies. Continuously tested against PHP-FPM 8.0 – 8.5 and FastCGI servers written in Go, Rust, C# and Java.