PHPackages                             khaiphan9x/fastcgi - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. khaiphan9x/fastcgi

ActiveLibrary[HTTP &amp; Networking](/categories/http)

khaiphan9x/fastcgi
==================

FastCGI Client implementation for PHP

v0.2.0(10y ago)03PHP

Since Jul 31Pushed 6y agoCompare

[ Source](https://github.com/khaiphan9x/fastcgi)[ Packagist](https://packagist.org/packages/khaiphan9x/fastcgi)[ Docs](http://www.github.com/ebernhardson/fastcgi/)[ RSS](/packages/khaiphan9x-fastcgi/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (3)Used By (0)

FastCGI Client
==============

[](#fastcgi-client)

Enables you to request script execution from a FastCGI server. FastCGI is a protocol commonly used for web servers to request script execution from a FastCGI daemoni like php-fpm.

Use Cases
---------

[](#use-cases)

- Executing any script that benefits from APC from the command line.
- Running code with an independent execution context from long running daemons
- More

Installation
------------

[](#installation)

```
$ composer require khaiphan9x/fastcgi

```

Usage
-----

[](#usage)

The client supports either tcp:

```
$client = new \EBernhardson\FastCGI\Client('localhost', '8989');

```

Or unix sockets:

```
$client = new \EBernhardson\FastCGI\Client('/var/run/php7-fpm.sock');

```

A FastCGI request is made using an array of environment parameters and a string containing the request content. When connecting to php-fpm the `$environment`will be available in `$_SERVER`. The following environment is the minimum required by php-fpm to execute a script.

```
$environment = [
    'REQUEST_METHOD'  => 'GET',
    'SCRIPT_FILENAME' => '/full/path/to/script.php',
];
$client->request($environment, '');

```

Once you have issued a request you must then fetch the response. The `response`method will block untill the request is complete.

```
$response = $client->response();

```

The `response` method returns an array with four keys: `statusCode`, `headers`, `body`, and `stderr`.

Currently you *MUST* call `response` before calling `request` again. Failure to do so will result in undefined behavior. The FastCGI protocol does support multiplexing so this may change in the future.

Exceptions
----------

[](#exceptions)

Any communication failures with the FastCGI daemon will result in an exception. The FastCGI `CommunicationException` extends from the SPL `RuntimeException`.

```
try {
    $client->request($environment, $stdin);
    $response = $client->response();
} catch (\EBernhardson\FastCGI\CommunicationException $failure) {
    // handle failure

}

```

Common environment variables passed over FastCGI
------------------------------------------------

[](#common-environment-variables-passed-over-fastcgi)

#### GATEWAY\_INTERFACE

[](#gateway_interface)

variable describing the version of the fastcgi protocol to use. Currently this client supports version 1.0.

```
'GATEWAY_INTERFACE' => 'FastCGI/1.0'

```

#### REQUEST\_METHOD

[](#request_method)

Required environment variable containing the method of the HTTP request.
Possible values include `GET`, `HEAD`, `POST`, `PUT` and `DELETE`.

```
'REQUEST_METHOD' => 'GET'

```

#### SCRIPT\_FILENAME

[](#script_filename)

Required environment variables containing the absolute path to the script being executed. This path must be accessible by the FastCGI server.

```
'SCRIPT_FILENAME' => '/home/zomg/deploy/current/web/app.php'

```

#### QUERY\_STRING

[](#query_string)

Optionally contains a query string. You can use the `http_build_query` function to format an array of key/value pairs in the expected format.

```
'QUERY_STRING' => http_build_query(['key' => 'value'])

```

#### SERVER\_SOFTWARE

[](#server_software)

The software used to make the FastCGI request.

```
'SERVER_SOFTWARE' => 'awesome-application/1.0'

```

#### SERVER\_NAME

[](#server_name)

The name of the server making this request

```
'SERVER_NAME' => php_uname('n')

```

#### CONTENT\_TYPE

[](#content_type)

When sending content along with the request, this specifies the mime type of the content.

```
'CONTENT_TYPE' => 'application/x-www-form-urlencoded'

```

#### CONTENT\_LENGTH

[](#content_length)

When sending content along with the request, this specifies the length of the content.

```
'CONTENT_LENGTH' => strlen($content)

```

Examples
--------

[](#examples)

#### Passing HTTP headers

[](#passing-http-headers)

Http headers are sent prefixed with HTTP\_.

```
$client->request(
    [
        'REQUEST_METHOD'  => 'GET',
        'SCRIPT_FILENAME' => '/full/path/to/test.php',
        'HTTP_ACCEPT'     => 'application/json',
    ],
    ''
);

```

#### POST Request

[](#post-request)

```
$content = 'key=value';
$client->request(
    [
        'REQUEST_METHOD'  => 'POST',
        'SCRIPT_FILENAME' => '/full/path/to/test.php',
        'CONTENT_TYPE'    => 'application/x-www-form-urlencoded',
        'CONTENT_LENGTH'  => strlen($content)
    ],
    $content
);

```

#### Response from php-fpm on invalid SCRIPT\_FILENAME

[](#response-from-php-fpm-on-invalid-script_filename)

```
array(4) {
  ["statusCode"]=>
  int(404)
  ["statusBody"]=>
  string(2) "OK"
  ["headers"]=>
  array(3) {
    ["status"]=>
    string(14) "404 Not Found"
    ["x-powered-by"]=>
    string(22) "PHP/5.4.9-4~precise+1"
    ["content-type"]=>
    string(9) "text/html"
  }
  ["body"]=>
  string(15) "File not found."
  ["stderr"]=>
  string(23) "Primary script unknown
"
}

```

#### Response from php-fpm on successfull execution

[](#response-from-php-fpm-on-successfull-execution)

```
array(4) {
  ["statusCode"]=>
  int(200)
  ["statusBody"]=>
  string(2) "OK"
  ["headers"]=>
  array(3) {
    ["x-powered-by"]=>
    string(22) "PHP/5.4.9-4~precise+1"
    ["content-type"]=>
    string(9) "text/html"
    ["status"]=>
    string(6) "200 OK"
  }
  ["body"]=>
  string(11) "Hello World"
  ["stderr"]=>
  string(0) ""
}

```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~404 days

Total

2

Last Release

3901d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2a50274b0a49f560e198bb7b54c5c47da564754d2c14b9a9d49c92f34a4346c8?d=identicon)[khaiphan9x](/maintainers/khaiphan9x)

---

Top Contributors

[![wagnert](https://avatars.githubusercontent.com/u/287509?v=4)](https://github.com/wagnert "wagnert (6 commits)")[![ebernhardson](https://avatars.githubusercontent.com/u/558434?v=4)](https://github.com/ebernhardson "ebernhardson (4 commits)")[![CatAnonymous](https://avatars.githubusercontent.com/u/25249169?v=4)](https://github.com/CatAnonymous "CatAnonymous (3 commits)")[![homeyjd](https://avatars.githubusercontent.com/u/1088185?v=4)](https://github.com/homeyjd "homeyjd (3 commits)")

---

Tags

fastcgiphp-fpmfpm

### Embed Badge

![Health badge](/badges/khaiphan9x-fastcgi/health.svg)

```
[![Health](https://phpackages.com/badges/khaiphan9x-fastcgi/health.svg)](https://phpackages.com/packages/khaiphan9x-fastcgi)
```

###  Alternatives

[friendsofsymfony/rest-bundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony

2.8k73.3M319](/packages/friendsofsymfony-rest-bundle)[php-http/discovery

Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations

1.3k309.5M1.2k](/packages/php-http-discovery)[gordalina/cachetool

Manage your OPcache &amp; APCu cache through the CLI

1.8k3.7M5](/packages/gordalina-cachetool)[ebernhardson/fastcgi

FastCGI Client implementation for PHP

49196.4k1](/packages/ebernhardson-fastcgi)[hollodotme/fast-cgi-client

A PHP fast CGI client to send requests (a)synchronously to PHP-FPM.

56423.9M25](/packages/hollodotme-fast-cgi-client)[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78126.4M414](/packages/react-http)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
