Search by

owner888 / php-http

owner888

Pure-PHP HTTP/1.1 and HTTP/2 client (ALPN, HPACK, pools, gzip, proxies) and WebSocket client, powered by owner888/php-async.

Package info

github.com/owner888/php-http

pkg:composer/owner888/php-http

Statistics

Installs: 23

Dependents: 1

Suggesters: 0

Stars: 1

Open Issues: 0

v1.1.0 2026-11-30 16:36 UTC

This package is auto-updated.

Last update: 2026-11-30 16:52:56 UTC


README

Pure-PHP 8.3+ 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. Socket I/O, DNS, TLS, Fibers and scheduling are provided by the standalone owner888/php-async dependency, with no HTTP-owned event loop.

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 in an existing event loop

The owner888/php-async dependency owns all readiness watchers, timers, and deferred callbacks. Standalone clients use its native loop; hosts such as Workerman can install their own Scheduler once and call HttpClient::send() or follow() inside the host Fiber. No secondary loop is created. See php-async's embedding guide for the Revolt adapter and GUI integration.

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