PHPackages                             varion/nghttp2 - 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. varion/nghttp2

ActivePhp-ext[HTTP &amp; Networking](/categories/http)

varion/nghttp2
==============

PHP extension for low-level HTTP/2 primitives powered by nghttp2

03C

Since Mar 9Pushed 3mo agoCompare

[ Source](https://github.com/varionlabs/ext-nghttp2)[ Packagist](https://packagist.org/packages/varion/nghttp2)[ RSS](/packages/varion-nghttp2/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependenciesVersions (1)Used By (0)

ext-nghttp2
===========

[](#ext-nghttp2)

This extension exposes nghttp2 as a Sans-I/O engine for PHP under the `Varion\\Nghttp2` namespace.

The extension does not perform socket I/O itself. Applications feed inbound bytes via `receive()` and collect outbound bytes via `drainOutput()`. Protocol events are then consumed using `nextEvent()`.

Quick Start
-----------

[](#quick-start)

### Install via PIE

[](#install-via-pie)

```
pie install varion/nghttp2
php -m | grep nghttp2
```

If you prefer enabling it persistently, add this to your `php.ini`:

```
extension=nghttp2
```

Uninstall:

```
pie uninstall varion/nghttp2
```

### Build from Source

[](#build-from-source)

```
phpize
./configure --enable-nghttp2
make -j"$(nproc)"
```

### Enable from Build Output

[](#enable-from-build-output)

```
php -d extension=$(pwd)/modules/nghttp2.so -m | grep nghttp2
```

Why Sans-I/O?
-------------

[](#why-sans-io)

Traditional HTTP libraries combine protocol logic with socket handling.

This extension separates them.

Benefits:

- easier integration with different event loops
- easier testing of protocol logic
- clearer separation between transport and HTTP/2 protocol layers

Architecture
------------

[](#architecture)

This extension exposes the nghttp2 HTTP/2 state machine to PHP while keeping all socket I/O outside the extension.

The extension operates as a Sans-I/O protocol engine.

Applications are responsible for:

- Transport (TCP/TLS sockets)
- Event loop integration
- Backpressure control
- Connection lifecycle

The extension is responsible for:

- HTTP/2 frame encoding and decoding
- Stream state machines
- Flow control
- Protocol event generation (`nextEvent()`)

Integration with Event Loops
----------------------------

[](#integration-with-event-loops)

Because the extension follows a Sans-I/O model, it can be integrated with different event loop implementations.

Possible integrations include:

- ReactPHP
- Amp
- custom polling loops
- future PHP polling/event APIs

Typical integration pattern:

1. Read bytes from a socket.
2. Pass them to `Session::receive()`.
3. Send outbound bytes from `drainOutput()`.
4. Process events using `nextEvent()`.

This design keeps transport concerns separate from the HTTP/2 protocol engine.

Transport Model
---------------

[](#transport-model)

This extension does not manage network sockets.

Applications must provide a transport layer, typically:

- TCP sockets
- TLS streams
- event-loop driven transports

Example responsibilities of the application:

- TLS negotiation
- ALPN validation
- socket read/write loops
- connection lifetime management

The extension focuses on HTTP/2 protocol processing and state transitions.

Quick Check
-----------

[](#quick-check)

```
php -d extension=$(pwd)/modules/nghttp2.so examples/session_basic.php
php -d extension=$(pwd)/modules/nghttp2.so examples/client-minimal.php
php -d extension=$(pwd)/modules/nghttp2.so examples/server-minimal.php 8080 --address=127.0.0.1
```

Minimal API Example
-------------------

[](#minimal-api-example)

```
