Skip to content

Instantly share code, notes, and snippets.

@masakielastic
masakielastic / http2-server.php
Last active March 7, 2026 05:42
Minimal HTTP/2 Server with ReactPHP Socket. The latest version is available at: https://github.com/masakielastic/http2-minimal-examples
<?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
@masakielastic
masakielastic / 01-http2-client.php
Last active March 7, 2026 05:42
Minimal HTTP/2 Client with ReactPHP Socket. The latest version is available at: https://github.com/masakielastic/http2-minimal-examples/tree/main
<?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
@masakielastic
masakielastic / README.md
Last active March 5, 2026 05:11
PHP 最小 HPACK:静的テーブル+表現パース/生成のみ

PHP 最小 HPACK:静的テーブル+表現パース/生成のみ

PHP で HTTP/2 の HPACK を最小実装。目的は HTTP/2 ヘッダーブロックの decode/encode を最小限に扱えるようにすることです。

スコープ(必須)

HPACK の静的テーブル(Static Table)だけを扱うこと

Dynamic Table は実装しない

@masakielastic
masakielastic / QuicInitialPacketParser.php
Created March 5, 2026 03:37
QUIC Initial Packet Parser (PHP)
<?php
declare(strict_types=1);
final class QuicInitialPacketParser
{
private string $buffer = '';
private int $offset = 0;
public function parse(string $packet): array
@masakielastic
masakielastic / README.md
Created March 4, 2026 06:58
Zig 0.15.2 で TCP クライアント

Zig 0.15.2 で TCP クライアント

zig run client.zig
@masakielastic
masakielastic / README.md
Last active March 4, 2026 06:33
Zig 0.15.2 で HTTP クライアント

Zig 0.15.2 で HTTP クライアント

zig run client.zig
@masakielastic
masakielastic / README.md
Created March 4, 2026 05:06
Zig 0.15 系で HTTP/1 サーバー

Zig 0.15 系で HTTP/1 サーバー

zig run server.zig
curl -v http//localhost:3000
@masakielastic
masakielastic / README.md
Last active March 3, 2026 23:08
PHP のストリーム関数で簡易 HTTP/2 クライアント・オブジェクト指向

PHP のストリーム関数で簡易 HTTP/2 クライアント・オブジェクト指向

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..........
@masakielastic
masakielastic / README.md
Created March 3, 2026 22:43
PHP のストリーム関数で簡易 HTTP/2 クライアント改善版

PHP のストリーム関数で簡易 HTTP/2 クライアント改善版

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..........
@masakielastic
masakielastic / README.md
Created March 3, 2026 22:27
PHP のストリーム関数で簡易 HTTP/2 クライアント (SETTINGS まで)

PHP のストリーム関数で簡易 HTTP/2 クライアント (SETTINGS まで)

実行結果

target: tls://142.250.192.164:443 (SNI/peer_name=www.google.com)
alpn_protocols(configured): h2,http/1.1
ALPN (negotiated): h2
>>> sending client preface (24 bytes)
&gt;&gt;&gt; sending SETTINGS (empty payload)