Skip to content

Instantly share code, notes, and snippets.

@masakielastic
masakielastic / README.md
Last active March 21, 2026 20:28
Zig で embed PHP を利用する

Zig で embed PHP を利用する

構成

build.zig 
c
src/main.zig

実行

@masakielastic
masakielastic / 2026plan.md
Last active March 21, 2026 11:18
PHP ビルトインサーバー改善案

2026年版 新計画

PHP Built-in Server (sapi/cli/php_cli_server.c) 再設計計画

0. この計画の目的

この計画の目的は、php_cli_server.c を一気に全面改修することではなく、次の 3 つの将来課題に耐えられる構造へ段階的に変えることです。

  1. http_parser 依存の緩和と将来の llhttp 移行準備
@masakielastic
masakielastic / stream-client.c
Last active March 21, 2026 20:40
embed PHP と Stream API で HTTP/1 クライアント。最新版は https://github.com/masakielastic/php-embed-stream-http
#include <php.h>
#include <Zend/zend_smart_str.h>
#include <sapi/embed/php_embed.h>
#include <main/php_streams.h>
static int run_min_client(void);
int main(int argc, char **argv)
{
PHP_EMBED_START_BLOCK(argc, argv)
@masakielastic
masakielastic / server.c
Last active March 21, 2026 20:40
embed PHP と Stream API で TLS HTTP/1 サーバー。最新版は https://github.com/masakielastic/php-embed-stream-http
#include <php.h>
#include <Zend/zend_smart_str.h>
#include <sapi/embed/php_embed.h>
#define SERVER_ADDR "tls://127.0.0.1:8443"
#define SERVER_CERT_PEM "localhost.pem"
#define SERVER_KEY_PEM "localhost-key.pem"
static int run_min_server(void);
static php_stream_context *create_tls_server_context(void);
@masakielastic
masakielastic / server.c
Last active March 21, 2026 20:41
embed PHP と Stream API で HTTP/1 サーバー。最新版は https://github.com/masakielastic/php-embed-stream-http
#include <php.h>
#include <Zend/zend_smart_str.h>
#include <sapi/embed/php_embed.h>
static int run_min_server(void);
int main(int argc, char **argv)
{
PHP_EMBED_START_BLOCK(argc, argv)
@masakielastic
masakielastic / php_rfc_style.md
Last active March 19, 2026 02:09
PHP RFC の書き方・議論スタイル共有メモ

PHP RFC の書き方・議論スタイル共有メモ

概要

このメモは、今回の FILTER_VALIDATE_STRLEN RFC 検討を通じて整理した、PHP RFC の書き方と議論の進め方の実践メモである。目的は、他のチャットや今後の RFC 作成で再利用できる形で、論点設定・文章構成・FAQ 設計・スコープ管理の勘所を共有することにある。


1. PHP RFC は「仕様書」だけではなく「公開討論のための設計文書」

PHP RFC は、単に機能仕様を列挙する文書ではない。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <netdb.h>
#include <sys/socket.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <openssl/x509_vfy.h>
@masakielastic
masakielastic / tls-client.c
Last active March 11, 2026 06:20
Minimal TLS Client in C with Explicit Connection State (QUIC Preparation)
/*
Minimal TLS Client in C (Architecture Exercise for QUIC Preparation)
This program implements a small TLS + TCP client using OpenSSL.
The goal of this code is not merely to demonstrate how to perform
a TLS request, but to illustrate a connection-oriented design that
resembles modern network protocol libraries.
Instead of writing everything inside main(), the implementation
intentionally separates responsibilities into multiple functions:
@masakielastic
masakielastic / reactphp_https_rr_example.php
Last active March 10, 2026 23:43
Minimal ReactPHP example for querying and parsing HTTPS DNS records (type 65)
<?php
/*
Minimal ReactPHP example for querying HTTPS DNS Resource Records (type 65).
This script demonstrates how to:
1. Query HTTPS DNS records using ReactPHP DNS
2. Retrieve raw RDATA from the DNS response
3. Parse SVCB/HTTPS wire format
4. Extract ALPN values such as "h2" and "h3"
@masakielastic
masakielastic / https_rr_parser.php
Last active March 10, 2026 23:15
Minimal PHP parser for HTTPS DNS Resource Record (type 65)
<?php
/*
Minimal HTTPS RR (DNS type 65) parser for PHP.
Demonstrates how to parse HTTPS/SVCB records returned by:
dns_get_record($host, 65, ..., true)
Extracts ALPN values such as "h2" and "h3".