PHP で HTTP/2 の HPACK を最小実装。目的は HTTP/2 ヘッダーブロックの decode/encode を最小限に扱えるようにすることです。
HPACK の静的テーブル(Static Table)だけを扱うこと
Dynamic Table は実装しない
| <?php | |
| /** | |
| * Minimal HTTP/2 Server with ReactPHP Socket (educational demo) | |
| * | |
| * This example demonstrates a minimal HTTP/2 server implemented directly | |
| * on top of ReactPHP's Socket component. It shows how HTTP/2 can be used | |
| * at the frame level without relying on external HTTP/2 libraries. | |
| * | |
| * The implementation is intentionally incomplete and simplified for |
| <?php | |
| /** | |
| * Minimal HTTP/2 Client with ReactPHP Socket (educational demo) | |
| * | |
| * This example demonstrates a minimal HTTP/2 client implemented directly | |
| * on top of ReactPHP's Socket component. It shows how HTTP/2 can be used | |
| * at the frame level without relying on external HTTP/2 libraries. | |
| * | |
| * The implementation is intentionally incomplete and simplified for |
| <?php | |
| declare(strict_types=1); | |
| final class QuicInitialPacketParser | |
| { | |
| private string $buffer = ''; | |
| private int $offset = 0; | |
| public function parse(string $packet): array |
target: tls://104.18.26.120:443 (SNI/peer_name=example.com)
alpn_protocols(configured): h2,http/1.1
ALPN (negotiated): h2
>>> sending client preface (24 bytes)
>>> sending SETTINGS (empty payload)
FRAME #0 len=18 type=0x04(SETTINGS) flags=0x00 sid=0
0000 00 03 00 00 00 64 00 04 00 01 00 00 00 05 00 ff .....d..........
target: tls://104.18.27.120:443 (SNI/peer_name=example.com)
alpn_protocols(configured): h2,http/1.1
ALPN (negotiated): h2
>>> sending client preface (24 bytes)
>>> sending SETTINGS (empty payload)
FRAME #0 len=18 type=0x04(SETTINGS) flags=0x00 sid=0
0000 00 03 00 00 00 64 00 04 00 01 00 00 00 05 00 ff .....d..........