amphp/hpack
Fast HPACK (HTTP/2 header compression) implementation for PHP by amphp. Provides efficient encoding/decoding of header blocks with dynamic tables, Huffman coding, and compliance-focused behavior, suitable for high-performance HTTP/2 clients and servers.
amphp/hpack is a low-level library for HTTP/2 header compression using HPACK (RFC 7541). It's primarily intended for use by HTTP/2 client/server implementations (e.g., amphp/http-server, amphp/http-client). To start:
composer require amphp/hpacksrc/ for the two core classes: StaticTable (immutable header table) and DynamicTable (mutable, per-connection)Encoder and Decoder classes to compress/decompress header setsuse function Amp\Http\Server\Encoder;
use function Amp\Http\Server\Decoder;
$encoder = new Encoder();
$decoder = new Decoder();
$headers = [[':method', 'GET'], [':path', '/']];
$encoded = $encoder->encode($headers); // returns binary string
$decoded = $decoder->decode($encoded); // returns original headers array
Check examples/ for basic round-trip use and consult unit tests (tests/) for edge cases.
Encoder/Decoder instances per-connection (HPACK is stateful due to dynamic table).amphp/socket, ReactPHP).Decoder/Encoder constructors (defaults to 4096 bytes; reduce for memory-constrained environments).amphp/http2 to validate compliance via unit tests (e.g., RFC test vectors in tests/RfcTest.php).Encoder emits DynamicTableSizeUpdate frames implicitly, but Decoder must be fed all table size change notifications in order. Ensure your HTTP/2 frame handler forwards them correctly.decode() throws Amp\Http\Server\HttpException on malformed input—always wrap in try/catch. Errors often indicate out-of-sync dynamic tables.Encoder/Decoder to inject custom header handling (e.g., logging, sensitive header redaction), but do not modify static/dynamic table internals.HPACK_DEBUG (if compiled with debug symbols) or log raw binary before/after encoding—compare with Wireshark captures for discrepancies.How can I help you explore Laravel packages today?