PHPackages                             rovazh/phpsocks - 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. rovazh/phpsocks

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

rovazh/phpsocks
===============

SOCKS5 proxy client, written in pure PHP with zero dependencies.

0.1.1(9mo ago)510.8k↑229.5%[1 issues](https://github.com/rovazh/phpsocks/issues)MITPHPPHP ^7.4 || ^8.0CI passing

Since Mar 1Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/rovazh/phpsocks)[ Packagist](https://packagist.org/packages/rovazh/phpsocks)[ RSS](/packages/rovazh-phpsocks/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (3)Dependencies (4)Versions (4)Used By (0)

[![PhpSocks Logo](.github/logo.png)](.github/logo.png)

PhpSocks
========

[](#phpsocks)

[![GitHub Actions Workflow Status](https://camo.githubusercontent.com/244e608bb6b35b1c555a4b9d711fafe40096a6210c30ca986dfba24d30bed93f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f726f76617a682f706870736f636b732f74657374732e796d6c)](https://camo.githubusercontent.com/244e608bb6b35b1c555a4b9d711fafe40096a6210c30ca986dfba24d30bed93f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f726f76617a682f706870736f636b732f74657374732e796d6c)[![GitHub Release](https://camo.githubusercontent.com/dd15119770817655bc38dda8c88e23f4fcc05825075a71fd6b0f1b6244616396/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f726f76617a682f706870736f636b73)](https://camo.githubusercontent.com/dd15119770817655bc38dda8c88e23f4fcc05825075a71fd6b0f1b6244616396/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f726f76617a682f706870736f636b73)

SOCKS5 proxy client, written in pure PHP with zero dependencies.

Features
--------

[](#features)

- Supports SOCKS5 protocol
- Implements the CONNECT command
- Implements UDP ASSOCIATE command
- Supports username/password authentication (RFC 1929)

Requirements
------------

[](#requirements)

- PHP 7.4 or higher
- Sockets extension enabled

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

[](#installation)

Install via Composer:

```
composer require rovazh/phpsocks
```

Usage
-----

[](#usage)

### Tunneling TCP connections through a SOCKS5 server (CONNECT)

[](#tunneling-tcp-connections-through-a-socks5-server-connect)

#### Plain TCP connections

[](#plain-tcp-connections)

The following example demonstrates connecting to `example.net` on port `80` via a SOCKS5 proxy server:

```
$client = new \PhpSocks\Client([
    'host' => '127.0.0.1', // SOCKS5 server (IPv4, IPv6, or hostname)
    'port' => 1080, // SOCKS5 server port
]);

try {
    $stream = $client->connect('tcp://example.net:80');
    $stream->write("GET / HTTP/1.0\r\n\r\n");
    echo $stream->read(1024);
    $stream->close();
} catch (\PhpSocks\Exception\PhpSocksException $e) {
    // Handle exception
}
```

#### Secure TLS connections

[](#secure-tls-connections)

The following example demonstrates establishing a secure TLS connection to `example.net` on port `443` via a SOCKS5 proxy server:

```
$client = new \PhpSocks\Client([
    'host' => '127.0.0.1',
    'port' => 1080,
]);

try {
    $stream = $client->connect('tls://example.net:443');
    $stream->write("GET / HTTP/1.0\r\n\r\n");
    echo $stream->read(1024);
    $stream->close();
} catch (\PhpSocks\Exception\PhpSocksException $e) {
    // Handle exception
}
```

The connect method accepts an associative array of [SSL context options](https://www.php.net/manual/en/context.ssl.php) that can be used to configure TLS settings when connecting to a destination host.

```
$client = new \PhpSocks\Client([
    'host' => '127.0.0.1',
    'port' => 1080,
]);

try {
    $stream = $client->connect('tls://example.net:443', [
        'tls' => [
            'verify_peer' => false,
        ]
    ]);
    $stream->write("GET / HTTP/1.0\r\n\r\n");
    echo $stream->read(1024);
    $stream->close();
} catch (\PhpSocks\Exception\PhpSocksException $e) {
    // Handle exception
}
```

> Note: SSL context options have no effect when using a plain TCP connection (tcp://).

#### Authentication

[](#authentication)

PhpSocks supports username/password authentication for SOCKS5 servers as defined in RFC 1929.

```
$client = new \PhpSocks\Client([
    'host' => '127.0.0.1',
    'port' => 1080,
    'auth' => [
        'username' => 'proxy_user',
        'password' => 'proxy_pass',
    ]
]);
```

#### Timeout Settings

[](#timeout-settings)

By default, the library relies on the system's [default\_socket\_timeout](https://www.php.net/manual/en/filesystem.configuration.php#ini.default-socket-timeout)when connecting to a SOCKS5 server. To set a custom timeout at runtime, use the `connect_timeout` option:

```
$client = new \PhpSocks\Client([
    'host' => '127.0.0.1',
    'port' => 1080,
    'connect_timeout' => 5.0, // 5 seconds
]);
```

Additionally, you can set a timeout for sending and receiving data. By default, this is determined by the operating system. To explicitly define it, use the `timeout` option:

```
$client = new \PhpSocks\Client([
    'host' => '127.0.0.1',
    'port' => 1080,
    'connect_timeout' => 5.0, // 5 seconds
    'timeout' => 3, // 3 seconds
]);
```

### Relaying UDP Datagrams through a SOCKS5 Server (UDP ASSOCIATE)

[](#relaying-udp-datagrams-through-a-socks5-server-udp-associate)

The following example establishes a SOCKS5 UDP association to enable relaying UDP datagrams to `example.net` on port `5023` via a SOCKS5 proxy server:

```
$client = new \PhpSocks\Client([
    'host' => '127.0.0.1', // SOCKS5 server (IPv4, IPv6, or hostname)
    'port' => 1080, // SOCKS5 server port
]);

try {
    $stream = $client->associate('udp://example.net:5023');
    $stream->write("Hello");
    echo $stream->read(1024);
    $stream->close();
} catch (\PhpSocks\Exception\PhpSocksException $e) {
    // Handle exception
}
```

License
-------

[](#license)

PhpSocks is distributed under the terms of the MIT License. See [LICENSE](LICENSE) file for details.

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance61

Regular maintenance activity

Popularity30

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity35

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 ~98 days

Total

3

Last Release

283d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b2db7034385a177f19430c9623a09f3f2b66a45036c6265c6d44bab5ce78c2fc?d=identicon)[Roman Vazhynskyi](/maintainers/Roman%20Vazhynskyi)

---

Top Contributors

[![rovazh](https://avatars.githubusercontent.com/u/61057791?v=4)](https://github.com/rovazh "rovazh (30 commits)")

---

Tags

clientphpphp-socksphp-socks5-proxyphp7phpsockssockssocks-proxysocks5socks clientsocks5php proxysocksphp socksphp socks5proxy client

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/rovazh-phpsocks/health.svg)

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

###  Alternatives

[clue/socks-react

Async SOCKS proxy connector client and server implementation, tunnel any TCP/IP-based protocol through a SOCKS5 or SOCKS4(a) proxy server, built on top of ReactPHP.

1181.1M33](/packages/clue-socks-react)

PHPackages © 2026

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