PHPackages                             anvilm/php.transport - 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. anvilm/php.transport

ActiveLibrary

anvilm/php.transport
====================

v3.0.0(1y ago)0151MITPHPPHP &gt;= 7.1

Since Jan 6Pushed 1y ago1 watchersCompare

[ Source](https://github.com/AnvilM/php.transport)[ Packagist](https://packagist.org/packages/anvilm/php.transport)[ RSS](/packages/anvilm-phptransport/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (9)Used By (1)

About
-----

[](#about)

This package is a client for PHP sockets and allows establishing TCP and UDP connections.

**Supported protocols:**

- TCP
- UDP
- TLS

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

[](#installation)

You can install this package using Composer:

```
composer require anvilm/php.transport
```

Basic Usage
-----------

[](#basic-usage)

### Create a client

[](#create-a-client)

#### TCP Client

[](#tcp-client)

Create a TCP client:

```
use AnvilM\Transport\Client

$client = Client::tcp('example.com:80');
```

#### UDP Client

[](#udp-client)

Create a UDP client:

```
use AnvilM\Transport\Client

$client = Client::upd('example.com:80');
```

#### TLS Client

[](#tls-client)

Create a TLS (SSL) client:

```
use AnvilM\Transport\Client

$client = Client::tls('example.com:80');
```

### Open connection

[](#open-connection)

To open a connection, use the open method:

```
use AnvilM\Transport\Client

$client = Client::tcp('example.com:80');

$timeout = 3; // Timeout in seconds

$client->open($timeout);
```

### Send packets

[](#send-packets)

To send packets, you can use the write method:

```
use AnvilM\Transport\Client

$client = Client::tcp('example.com:80');

$data = 'hello'; // Data to send
$timeout = 30; // Write timeout
$length = strlen($data); // Length of data to send

// Open connection and send packet
$client->open()->write(pack('V', $data), $length);
```

### Read packets

[](#read-packets)

To read received data, use the read method:

```
use AnvilM\Transport\Client

$client = Client::tcp('example.com:80');

$length = 1024; // Length of data for read
$timeout = 30; // Timeout to wait for data from server

// Open connection and read data
$data = $client->open()->read($length, $timeout);
```

### Close connection

[](#close-connection)

After closing the connection, you can immediately open a similar one, as a new socket is created upon closing.

```
use AnvilM\Transport\Client

$client = Client::tcp('example.com:80')->open()
    ->close()
    ->open();
```

### Context

[](#context)

ВYou can also use a context if necessary. This code creates and sets parameters for stream\_context\_create. Currently, all context parameters are available for TCP, UDP, and TLS (SSL) connections.

You can also modify this context, as the context resource will be changed by reference.

```
use AnvilM\Transport\Client
use AnvilM\Transport\Connection\Context\TLSContext;

$context = (new TLSContext())->timeout(5.5)
    ->verifyPeer(true)
    ->verifyPeerName(true);

$client = Client::tls('example.com:443', $context);

$client->open(); // Open with timeout 5.5

$context->timeout(10); // Set new timeout

$data = $client->read(); // Read data with new timeout
```

### Socket

[](#socket)

You can get the socket object if you need manual connection management:

```
use AnvilM\Transport\Client
use AnvilM\Transport\Connection\Socket\Socket;

$client = Client::tcp('example.com:443');

$socket = $client->getSocket();

$socket->open()->enableCrypto();
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance41

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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 ~0 days

Total

7

Last Release

495d ago

Major Versions

v1.0.4 → v2.0.02025-01-08

v2.0.0 → v3.0.02025-01-08

PHP version history (2 changes)v1.0.0PHP &gt;= 7.0

v1.0.3PHP &gt;= 7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/d6be63d2e00c01cda03e8e0a314d1714133bc0839da7adb72ef75afa8e7972af?d=identicon)[AnvilM](/maintainers/AnvilM)

---

Top Contributors

[![AnvilM](https://avatars.githubusercontent.com/u/94012493?v=4)](https://github.com/AnvilM "AnvilM (17 commits)")

### Embed Badge

![Health badge](/badges/anvilm-phptransport/health.svg)

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

PHPackages © 2026

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