Minimal HTTP/2 client and server examples implemented in pure PHP using ReactPHP Socket.
The goal of this repository is educational: to demonstrate the HTTP/2 connection flow and frame-level behavior without relying on external HTTP/2 libraries.
Instead of using full implementations such as nghttp2, these examples show how HTTP/2 works internally by implementing a very small subset of the protocol.
These examples are intentionally minimal and incomplete.
They are designed for learning and experimentation only.
They do NOT implement the full HTTP/2 specification and must not be used in production.
Limitations include:
- single request/response flow
- minimal frame handling
- no HPACK implementation
- no advanced flow control
- no error handling for many edge cases
- HTTP/2 connection preface
- SETTINGS exchange
- HEADERS and DATA frame flow
- minimal HTTP/2 request/response lifecycle
- cleartext HTTP/2 (h2c, prior knowledge)
- TLS HTTP/2 with ALPN
This repository is useful if you want to:
- understand HTTP/2 at the frame level
- experiment with HTTP/2 without large dependencies
- build educational tools or protocol experiments
Client Server
| |
| connection preface |
| SETTINGS -----------------------> |
| |
| SETTINGS |
| <------------------------------- |
| request HEADERS / DATA ---------> |
| |
| response HEADERS
| <------------------------------- |
| response DATA
| <------------------------------- |
http2-client.php
http2-server.php
docs/
client-explained.md
server-explained.md
PHP 7.1 or later
Composer
ReactPHP
Install dependencies:
git clone https://github.com/masakielastic/http2-minimal-examples
cd http2-minimal-examples
composer install
php http2-server.php 8080
Test with curl:
curl --http2-prior-knowledge http://127.0.0.1:8080/
Explanation:
--http2-prior-knowledgeskips HTTP/1.1 upgrade- the client immediately starts HTTP/2
php http2-server.php 8443 server.key server.crt
Test with curl:
curl -k -v --http2 https://127.0.0.1:8443/
Options explained:
--http2enables HTTP/2 negotiation-kignores certificate verification (for local testing)
php http2-client.php http://127.0.0.1:8080/
Step-by-step explanations of the HTTP/2 protocol flow implemented in this repository.
- Client walkthrough: docs/client-explained.md
- Server walkthrough: docs/server-explained.md
If you want to explore further:
- HTTP/2 specification (RFC 9113)
- HPACK header compression
- flow control
- stream multiplexing
These examples intentionally omit many of these features to keep the code readable.
This repository provides a small, readable reference implementation that demonstrates the core mechanics of HTTP/2.
It is particularly useful for:
- protocol learners
- library authors
- developers experimenting with HTTP/2 internals