Skip to content
Muhammet Şafak edited this page May 24, 2026 · 2 revisions

InitPHP Socket — Wiki

Welcome to the official documentation for initphp/socket — a lightweight TCP, UDP, TLS and SSL socket server / client toolkit for PHP 8.1+.

composer require initphp/socket
use InitPHP\Socket\Socket;
use InitPHP\Socket\Enum\Transport;

$server = Socket::server(Transport::TCP, '127.0.0.1', 8080);
$server->listen();
$server->live(function ($srv, $conn) {
    $payload = $conn->read(1024);
    if ($payload !== null) {
        $conn->write("echo: {$payload}");
    }
});

The package gives you four building blocks every long-running PHP service ends up writing by hand:

Layer Class / Concept Purpose
Factory Socket::server() / Socket::client() One entry point dispatching by Transport enum
Servers Server\{TCP, UDP, TLS, SSL} Bind, listen and dispatch with a select-driven loop
Clients Client\{TCP, UDP, TLS, SSL} Connect-read-write to a remote endpoint
Channels Channel\{Tcp, Udp, Stream}Channel Per-transport I/O strategy used by ServerConnection

Start here

  • Installation — composer, requirements, optional extensions.
  • Quick Start — bind, accept, echo in under 20 lines.
  • Architecture — how the factory, channels, loop and connections fit together.

Transports

API

Recipes

Operational


2.x line · PHP 8.1+ · MIT · GitHub · Packagist

Clone this wiki locally