varion / driver-stream
PHP stream driver for the Varion Transport API
v0.1.0
2026-03-07 17:34 UTC
Requires
- php: ^8.1
- varion/transport-contracts: ^0.1
Requires (Dev)
- phpunit/phpunit: ^10.5
README
varion/driver-stream is a stream-based transport driver for the experimental Varion Transport API.
It is the first concrete driver implementation for varion/transport-contracts, built only with standard PHP stream/socket functions.
Scope
This package currently provides:
- outgoing TCP connections
- listening TCP servers
- read/write operations
- close operations
- local/remote address retrieval
This is a v0.1 reference implementation and uses blocking I/O by default.
Requirements
- PHP
^8.1 varion/transport-contracts^0.1
Supported options
StreamDriver::connect(string $uri, array $options = [])
timeout(int|float): connection timeout secondscontext(array): stream context optionsflags(int): flags forstream_socket_client()blocking(bool): appliesstream_set_blocking()after connection
StreamDriver::listen(string $uri, array $options = [])
context(array): stream context optionsflags(int): flags forstream_socket_server()backlog(int): mapped tocontext['socket']['backlog']blocking(bool): appliesstream_set_blocking()after listener creation
Usage
<?php declare(strict_types=1); use Varion\Transport\Driver\Stream\StreamDriver; $driver = new StreamDriver(); $conn = $driver->connect('tcp://127.0.0.1:8080'); $conn->write("hello\n"); echo $conn->read(1024); $conn->close();
Server example:
<?php declare(strict_types=1); use Varion\Transport\Driver\Stream\StreamDriver; $driver = new StreamDriver(); $listener = $driver->listen('tcp://127.0.0.1:8080'); while ($conn = $listener->accept()) { $data = $conn->read(1024); $conn->write("HTTP/1.0 200 OK\r\nContent-Length: 2\r\n\r\nOK"); $conn->close(); }
Limitations
- blocking I/O oriented design
- no TLS abstraction layer beyond native stream context options
- no event loop integration