Minimal HTTP server PHP extension powered by h2o

Maintainers

Package info

github.com/masakielastic/php-ext-h2o

Language:C

Type:php-ext

Ext name:ext-h2o

pkg:composer/masakielastic/h2o

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

0.1.0 2026-02-25 06:56 UTC

This package is auto-updated.

Last update: 2026-02-25 07:00:55 UTC


README

Minimal PHP extension that embeds an h2o-based HTTP server.

Current status

  • Extension name: h2o
  • Main API: h2o_server_run(array $options = null): bool
  • Build path for PIE: ext

Requirements

  • PHP development tools (phpize, headers)
  • h2o shared library installed under $HOME/.local
    • required: $HOME/.local/include/h2o.h
    • required: $HOME/.local/lib/libh2o.so
  • libuv and OpenSSL from Debian packages
    • headers: /usr/include/uv.h (or /usr/include/libuv.h)
    • libs: /usr/lib/x86_64-linux-gnu/libuv.so, libssl.so, libcrypto.so

Build (manual)

cd ext
phpize
./configure --enable-h2o --with-h2o-dir=$HOME/.local --with-libuv-dir=/usr --with-openssl-dir=/usr
make -j"$(nproc)"

Load extension

php -n -d extension=$(pwd)/ext/modules/h2o.so -r 'var_dump(function_exists("h2o_server_run"));'

API

h2o_server_run(array $options = null): bool

Supported options:

  • host (string, default 0.0.0.0)
  • port (int, default 8080)
  • response_body (string, default "OK\\n")
  • tls_cert (string, optional)
  • tls_key (string, optional)

Notes:

  • tls_cert and tls_key must be set together.
  • The function blocks while the server loop is running.
  • Stop with Ctrl+C (SIGINT).

PIE

pie install

composer.json is configured as type: php-ext with php-ext.build-path: ext.

In non-interactive environments, PIE can finish build but fail at the final enable step if sudo prompt is required.

Tests

cd ext
phpize
./configure --enable-h2o --with-h2o-dir=$HOME/.local
make -j"$(nproc)"
REPORT_EXIT_STATUS=1 NO_INTERACTION=1 make test TESTS='tests/*.phpt'