Search by

owner888 / php-http

owner888

Zero-dependency pure-PHP 8.3+ async event loop (stream_select / Io\Poll + Fibers), non-blocking DNS/TLS sockets, HTTP/1.1 & HTTP/2 client (ALPN, HPACK, connection pools, gzip, HTTP/SOCKS5 proxies), and WebSocket client.

Package info

github.com/owner888/php-http

pkg:composer/owner888/php-http

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-11-25 21:44 UTC

This package is auto-updated.

Last update: 2026-11-25 21:52:05 UTC


README

Zero-dependency pure-PHP 8.3+ coroutine event loop (stream_select / PHP 8.6 Io\Poll + Fiber), non-blocking DNS and TLS sockets, HTTP/1.1 & HTTP/2 client (ALPN negotiation, HPACK header compression, multiplexed streams, connection pools, gzip decompression, HTTP CONNECT & SOCKS5 proxies, chunked upload progress), and WebSocket client.

Shared by MyPHP and pig. No ext-curl or C extension required beyond PHP's standard ext-openssl.

Installation

composer require owner888/php-http

Quick Start

Concurrent HTTP/2 Requests with Fibers

<?php
use Owner888\Async\Async;
use Owner888\Http\{HttpClient, Request};

Async::run(function (): void {
    $client = new HttpClient(timeout: 15.0);

    // 8 concurrent requests multiplexed over a single HTTP/2 connection:
    $futures = [];
    for ($i = 0; $i < 8; $i++) {
        $futures[] = Async::spawn(function () use ($client, $i): string {
            $res = $client->follow(new Request(
                'GET',
                "https://api.binance.com/api/v3/klines?symbol=BTCUSDT&interval=5m&limit=1000",
                ['Accept-Encoding' => 'gzip'],
            ));
            return $res->body->all();
        });
    }

    foreach ($futures as $f) {
        $body = $f->await();
        echo strlen($body), " bytes\n";
    }
});

Embedding inside a GUI Event Loop (Loop::turn())

When a host framework (such as a native GUI run loop) owns the main thread, drive the loop without blocking via Loop::turn():

use Owner888\Async\Loop;

// Inside your 2ms GUI timer callback while requests are in flight:
Loop::get()->turn();

Proxies & Custom CA Certificates

use Owner888\Async\Socket;
use Owner888\Http\{HttpClient, Proxy};

// Honor HTTP_PROXY / HTTPS_PROXY / ALL_PROXY / NO_PROXY:
$client = new HttpClient(proxy: Proxy::fromEnvironment(getenv()));

// Or explicit HTTP / SOCKS5 proxy:
$client = new HttpClient(proxy: Proxy::parse('socks5://127.0.0.1:1080'));

// Trust an additional CA certificate (or set SSL_CERT_FILE in the environment):
Socket::useExtraCaFile('/path/to/custom-ca.pem');

WebSocket Client

use Owner888\Async\Async;
use Owner888\Http\WebSocket;

Async::run(function (): void {
    $ws = WebSocket::connect('wss://echo.websocket.events', []);
    $ws->send('hello');
    echo $ws->receive(), "\n";
    $ws->close();
});

License

MIT