PHPackages                             innmind/socket - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. innmind/socket

Abandoned → [innmind/io](/?search=innmind%2Fio)ArchivedLibrary[Utility &amp; Helpers](/categories/utility)

innmind/socket
==============

Wrapper to PHP socket functions

6.1.0(2y ago)186.5k↓38.3%1[1 issues](https://github.com/Innmind/Socket/issues)3MITPHPPHP ~8.1

Since Jul 23Pushed 2y ago1 watchersCompare

[ Source](https://github.com/Innmind/Socket)[ Packagist](https://packagist.org/packages/innmind/socket)[ Docs](http://github.com/Innmind/Socket)[ RSS](/packages/innmind-socket/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (4)Dependencies (8)Versions (14)Used By (3)

Socket
======

[](#socket)

[![Build Status](https://github.com/innmind/socket/workflows/CI/badge.svg?branch=master)](https://github.com/innmind/socket/actions?query=workflow%3ACI)[![codecov](https://camo.githubusercontent.com/be2d5c72cd921ffb9cd6686276474f06c18db42b929d1880c3669c046ac69969/68747470733a2f2f636f6465636f762e696f2f67682f696e6e6d696e642f736f636b65742f6272616e63682f646576656c6f702f67726170682f62616467652e737667)](https://codecov.io/gh/innmind/socket)[![Type Coverage](https://camo.githubusercontent.com/c19b046445bdd098ebafe44e2cbee030aa71c43f92c6244e331cac88ee87cb9b/68747470733a2f2f73686570686572642e6465762f6769746875622f696e6e6d696e642f736f636b65742f636f7665726167652e737667)](https://shepherd.dev/github/innmind/socket)

Layer on top of [`innmind/stream`](https://github.com/Innmind/Stream) to specifically work with sockets.

Installation
------------

[](#installation)

```
composer require innmind/socket
```

Usage
-----

[](#usage)

### Unix socket

[](#unix-socket)

Server example:

```
use Innmind\Socket\{
    Server\Unix,
    Address\Unix as Address,
};
use Innmind\TimeContinuum\Earth\ElapsedPeriod;
use Innmind\Stream\Watch\Select;

$server = Unix::recoverable(Address::of('/tmp/my-socket'))->match(
    static fn($server) => $server,
    static fn() => throw new \RuntimeException('Unable to create socket'),
);
$select = Select::timeoutAfter(new ElapsedPeriod(100))
    ->forRead($server);

do {
    $select()
        ->flatMap(fn($ready) => $ready->toRead()->find(fn($stream) => $stream === $server))
        ->flatMap(fn($server) => $server->accept())
        ->match(
            static fn($incomingConnection) => $doSomething($incomingConnection),
            static fn() => null, // no incoming connection within the last 100 milliseconds
        )
} while (true);
```

The example above creates a socket at `/tmp/my-socket.sock` and will wait indefinitely. It will call `$doSomething()` with an incoming connection as soon as one is available.

Client example:

```
use Innmind\Socket\{
    Client\Unix,
    Address\Unix as Address,
};

$client = Unix::of(Address::of('/tmp/my-socket'))->match(
    static fn($client) => $client,
    static fn() => throw new \RuntimeException('Unable to connect to socket'),
);
$client->write(Str::of('hello there!'))->match(
    static fn($client) => $continueToDoSomething($client),
    static fn($error) => null, // do something else when it failed to write to the socket
);
```

This will simply connect to the socket server declared above and will send the data `hello there!`.

If you want to read what the server send back you should use the stream [`Select`](https://github.com/Innmind/Stream#usage) in order to wait for the data to arrive.

### Internet socket

[](#internet-socket)

Same logic as the unix socket except the way you build the server:

```
use Innmind\Socket\{
    Server\Internet,
    Internet\Transport,
};
use Innmind\IP\IPv4;
use Innmind\Url\Authority\Port;

$server = Internet::of(
    Transport::tcp(),
    IPv4::of('127.0.0.1'),
    Port::of(80),
);
//this will listen for incoming tcp connection on the port 80
```

and the client:

```
use Innmind\Socket\{
    Client\Internet,
    Internet\Transport,
};
use Innmind\Url\Url;

$client = Internet::of(
    Transport::tcp(),
    Url::of('//127.0.0.1:80')->authority(),
);
//this will connect to a local socket on port 80
```

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity33

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity79

Established project with proven stability

 Bus Factor1

Top contributor holds 98.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~204 days

Recently: every ~238 days

Total

12

Last Release

974d ago

Major Versions

1.2.0 → 2.0.02018-11-11

2.1.0 → 3.0.02020-01-06

3.1.0 → 4.0.02022-02-22

4.0.0 → 5.0.02022-07-14

5.0.0 → 6.0.02023-01-29

PHP version history (5 changes)1.0.0PHP ~7.1

2.0.0PHP ~7.2

3.0.0PHP ~7.4

3.1.0PHP ~7.4|~8.0

4.0.0PHP ~8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/851425?v=4)[Baptiste Langlade](/maintainers/Baptouuuu)[@Baptouuuu](https://github.com/Baptouuuu)

---

Top Contributors

[![Baptouuuu](https://avatars.githubusercontent.com/u/851425?v=4)](https://github.com/Baptouuuu "Baptouuuu (90 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")

---

Tags

Socket

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/innmind-socket/health.svg)

```
[![Health](https://phpackages.com/badges/innmind-socket/health.svg)](https://phpackages.com/packages/innmind-socket)
```

###  Alternatives

[trafficcophp/bytebuffer

Node.js inspired byte stream buffer for PHP.

33437.2k17](/packages/trafficcophp-bytebuffer)[zoon/rialto

Manage Node resources from PHP

12199.4k3](/packages/zoon-rialto)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
