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.
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.
- PHP
^8.1 varion/transport-contracts^0.1
timeout(int|float): connection timeout secondscontext(array): stream context optionsflags(int): flags forstream_socket_client()blocking(bool): appliesstream_set_blocking()after connection
context(array): stream context optionsflags(int): flags forstream_socket_server()backlog(int): mapped tocontext['socket']['backlog']blocking(bool): appliesstream_set_blocking()after listener creation
<?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();
}- blocking I/O oriented design
- no TLS abstraction layer beyond native stream context options
- no event loop integration