PHPackages                             lisachenko/protocol-fcgi - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. lisachenko/protocol-fcgi

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

lisachenko/protocol-fcgi
========================

Implementation of the FastCGI (FCGI) protocol in PHP

4.0.0(2w ago)126105.0k↓17.3%102MITPHPPHP &gt;=8.4CI passing

Since Sep 8Pushed 2w ago9 watchersCompare

[ Source](https://github.com/lisachenko/protocol-fcgi)[ Packagist](https://packagist.org/packages/lisachenko/protocol-fcgi)[ GitHub Sponsors](https://github.com/lisachenko)[ RSS](/packages/lisachenko-protocol-fcgi/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (6)Dependencies (4)Versions (13)Used By (2)

PHP FastCGI Protocol
====================

[](#php-fastcgi-protocol)

[![CI](https://github.com/lisachenko/protocol-fcgi/actions/workflows/ci.yml/badge.svg)](https://github.com/lisachenko/protocol-fcgi/actions/workflows/ci.yml)[![PHPStan Badge](https://camo.githubusercontent.com/0a4a165e52b97c48ed6b3e1c246461f2c723c523a939546e8f5fdf5790adb3dd/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c2532306d61782d627269676874677265656e2e7376673f7374796c653d666c6174266c696e6b3d68747470732533412532462532467068707374616e2e6f7267253246757365722d677569646525324672756c652d6c6576656c73)](https://camo.githubusercontent.com/0a4a165e52b97c48ed6b3e1c246461f2c723c523a939546e8f5fdf5790adb3dd/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c2532306d61782d627269676874677265656e2e7376673f7374796c653d666c6174266c696e6b3d68747470732533412532462532467068707374616e2e6f7267253246757365722d677569646525324672756c652d6c6576656c73)[![Latest Version](https://camo.githubusercontent.com/83c34173457df01fc599ddfa3da40abb491e2ffd3ba5fc8a018b9addc3d697e4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c6973616368656e6b6f2f70726f746f636f6c2d666367692e737667)](https://packagist.org/packages/lisachenko/protocol-fcgi)[![Total Downloads](https://camo.githubusercontent.com/2a8b06c30d8b9db21cf19a4e71cda9942b861ac76ee35fc8f14dff5a28569bd5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c6973616368656e6b6f2f70726f746f636f6c2d666367692e737667)](https://packagist.org/packages/lisachenko/protocol-fcgi)[![Daily Downloads](https://camo.githubusercontent.com/9f8228e36f9ee3b8dfb452ea960492da201ca894114ea192e0fa1ef28f27a83d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64642f6c6973616368656e6b6f2f70726f746f636f6c2d666367692e737667)](https://packagist.org/packages/lisachenko/protocol-fcgi)[![Minimum PHP Version](https://camo.githubusercontent.com/db2abc4c99337a799d57b191c749e512b551eaebf6ce7c37e0ea9eac2eb1b9f6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230382e342d3838393242462e737667)](https://www.php.net/supported-versions.php)[![License](https://camo.githubusercontent.com/b16c28d458f467957bdf3816987da51bb46a177a8971f070bd0774b263508f87/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6c6973616368656e6b6f2f70726f746f636f6c2d666367692e737667)](https://packagist.org/packages/lisachenko/protocol-fcgi)

A **zero-dependency, object-oriented implementation of the FastCGI 1.0 binary protocol** for PHP.

FastCGI is the battle-tested protocol that web servers like nginx, Apache and Caddy use to talk to `php-fpm` — billions of requests flow through it every day. This library gives you the protocol itself as a clean, strictly-typed PHP API, so you can build your own high-performance FastCGI **clients** (talk to `php-fpm` directly, no web server in between) and **servers** (long-running PHP daemons that nginx can speak to natively).

✨ Key Features
--------------

[](#-key-features)

- 📦 **Complete protocol coverage** — all 11 FastCGI record types, including the management records (`GET_VALUES`, `GET_VALUES_RESULT`, `UNKNOWN_TYPE`)
- 🌊 **Streaming frame parser** — feed partial socket reads into `FrameParser::hasFrame()` / `parseFrame()` and get fully-typed record objects out as soon as they are complete
- 🔄 **Byte-exact round-tripping** — every record packs back to the exact wire bytes it was parsed from; the test suite is pinned to hex fixtures captured from real traffic
- 📏 **Automatic 8-byte padding** — content alignment is handled for you, as the spec recommends
- 🏷️ **Full name-value pair encoding** — including the 4-byte long form for names and values over 127 bytes
- 🎯 **Native enums for the protocol vocabulary** — record types, roles and protocol statuses are backed enums (`RecordType`, `Role`, `ProtocolStatus`), so invalid wire values fail fast with a dedicated `ProtocolException`
- 🪶 **Zero runtime dependencies** — pure PHP, nothing but the language itself
- 🔒 **Strict types + PHPStan at the maximum level** — the whole codebase (tests included) passes static analysis at the strictest setting

Requirements
------------

[](#requirements)

- PHP &gt;= 8.4

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

[](#installation)

```
composer require lisachenko/protocol-fcgi
```

Usage
-----

[](#usage)

The library implements both sides of the wire: use it to *send* FastCGI requests as a client, or to *receive* and answer them as a server. The full protocol specification is available at [fast-cgi.github.io/spec](https://fast-cgi.github.io/spec).

### FastCGI client: query php-fpm directly

[](#fastcgi-client-query-php-fpm-directly)

```
