PHPackages                             clue/socks-server - 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. [Queues &amp; Workers](/categories/queues)
4. /
5. clue/socks-server

Abandoned → [clue/socks-react](/?search=clue%2Fsocks-react)Library[Queues &amp; Workers](/categories/queues)

clue/socks-server
=================

Async SOCKS proxy server (SOCKS4, SOCKS4a and SOCKS5), built on top of React PHP

v0.7.0(9y ago)26404↓100%8MITPHPPHP &gt;=5.3

Since Nov 7Pushed 9y ago2 watchersCompare

[ Source](https://github.com/clue-legacy/php-socks-server)[ Packagist](https://packagist.org/packages/clue/socks-server)[ Docs](https://github.com/clue/php-socks-server)[ RSS](/packages/clue-socks-server/feed)WikiDiscussions master Synced 2mo ago

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

Deprecation notice
==================

[](#deprecation-notice)

This package has now been merged into [clue/socks-react](https://github.com/clue/php-socks-react) and only exists for BC reasons.

```
$ composer require clue/socks-react
```

If you've previously used this package to build a SOCKS server, upgrading should take no longer than a few minutes. All classes have been merged as-is from the latest `v0.7.0` release with no other changes, so you can simply update your code to use the updated namespace like this:

```
// old from clue/socks-server
$server = new Clue\React\Socks\Server\Server($loop, $socket);

// new
$server = new Clue\React\Socks\Server($loop, $socket);
```

See  for more details.

The below documentation applies to the last release of this package. Further development will take place in the updated [clue/socks-react](https://github.com/clue/php-socks-react), so you're highly recommended to upgrade as soon as possible.

Legacy clue/socks-server [![Build Status](https://camo.githubusercontent.com/1efb35c1516c233f63c36c5c11b72d9ec68361d67cf8df87e97058e3eab68b4a/68747470733a2f2f7472617669732d63692e6f72672f636c75652f7068702d736f636b732d7365727665722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/clue/php-socks-server)
=======================================================================================================================================================================================================================================================================================================================

[](#legacy-cluesocks-server-)

Async SOCKS proxy server (SOCKS4, SOCKS4a and SOCKS5), built on top of React PHP.

The SOCKS protocol family can be used to easily tunnel TCP connections independent of the actual application level protocol, such as HTTP, SMTP, IMAP, Telnet etc.

**Table of contents**

- [Quickstart example](#quickstart-example)
- [Usage](#usage)
    - [Server](#server)
        - [Protocol version](#protocol-version)
        - [Authentication](#authentication)
        - [Proxy chaining](#proxy-chaining)
- [Install](#install)
- [Tests](#tests)
- [License](#license)
- [More](#more)

Quickstart example
------------------

[](#quickstart-example)

Once [installed](#install), you can use the following code to create a SOCKS proxy server listening for connections on `localhost:1080`:

```
$loop = React\EventLoop\Factory::create();

// listen on localhost:1080
$socket = new Socket($loop);
$socket->listen(1080,'localhost');

// start a new server listening for incoming connection on the given socket
$server = new Server($loop, $socket);

$loop->run();
```

See also the [examples](examples).

Usage
-----

[](#usage)

### Server

[](#server)

The `Server` is responsible for accepting incoming communication from SOCKS clients and forwarding the requested connection to the target host. It also registers everything with the main [`EventLoop`](https://github.com/reactphp/event-loop#usage)and an underlying TCP/IP socket server like this:

```
$loop = \React\EventLoop\Factory::create();

// listen on localhost:$port
$socket = new Socket($loop);
$socket->listen($port,'localhost');

$server = new Server($loop, $socket);
```

If you need custom connector settings (DNS resolution, timeouts etc.), you can explicitly pass a custom instance of the [`ConnectorInterface`](https://github.com/reactphp/socket#connectorinterface):

```
// use local DNS server
$dnsResolverFactory = new DnsFactory();
$resolver = $dnsResolverFactory->createCached('127.0.0.1', $loop);

// outgoing connections to target host via interface 192.168.10.1
$connector = new DnsConnector(
    new TcpConnector($loop, array('bindto' => '192.168.10.1:0')),
    $resolver
);

$server = new Server($loop, $socket, $connector);
```

#### Protocol version

[](#protocol-version)

The `Server` supports all protocol versions (SOCKS4, SOCKS4a and SOCKS5) by default.

While SOCKS4 already had (a somewhat limited) support for `SOCKS BIND` requests and SOCKS5 added generic UDP support (`SOCKS UDPASSOCIATE`), this library focuses on the most commonly used core feature of `SOCKS CONNECT`. In this mode, a SOCKS server acts as a generic proxy allowing higher level application protocols to work through it.

   SOCKS4 SOCKS4a SOCKS5   Protocol specification [SOCKS4.protocol](http://ftp.icm.edu.pl/packages/socks/socks4/SOCKS4.protocol) [SOCKS4A.protocol](http://ftp.icm.edu.pl/packages/socks/socks4/SOCKS4A.protocol) [RFC 1928](http://tools.ietf.org/html/rfc1928)   Tunnel outgoing TCP connections ✓ ✓ ✓   Remote DNS resolving ✗ ✓ ✓   IPv6 addresses ✗ ✗ ✓   [Username/Password authentication](#authentication) ✗ ✗ ✓ (as per [RFC 1929](http://tools.ietf.org/html/rfc1929))   Handshake # roundtrips 1 1 2 (3 with authentication)   Handshake traffic
+ remote DNS 17 bytes
✗ 17 bytes
+ hostname + 1 *variable* (+ auth + IPv6)
+ hostname - 3 Note, this is **not** a full SOCKS5 implementation due to missing GSSAPI authentication (but it's unlikely you're going to miss it anyway).

If want to explicitly set the protocol version, use the supported values `4`, `4a` or `5`:

```
$server->setProtocolVersion(5);
```

In order to reset the protocol version to its default (i.e. automatic detection), use `null` as protocol version.

```
$server->setProtocolVersion(null);
```

#### Authentication

[](#authentication)

By default, the `Server` does not require any authentication from the clients. You can enable authentication support so that clients need to pass a valid username and password before forwarding any connections.

Setting authentication on the `Server` enforces each further connected client to use protocol version 5 (SOCKS5). If a client tries to use any other protocol version, does not send along authentication details or if authentication details can not be verified, the connection will be rejected.

Because your authentication mechanism might take some time to actually check the provided authentication credentials (like querying a remote database or webservice), the server side uses a [Promise](https://github.com/reactphp/promise) based interface. While this might seem complex at first, it actually provides a very simple way to handle simultanous connections in a non-blocking fashion and increases overall performance.

```
$server->setAuth(function ($username, $password) {
    // either return a boolean success value right away
    // or use promises for delayed authentication
});
```

Or if you only accept static authentication details, you can use the simple array-based authentication method as a shortcut:

```
$server->setAuthArray(array(
    'tom' => 'password',
    'admin' => 'root'
));
```

See also the [second example](examples).

If you do not want to use authentication anymore:

```
$server->unsetAuth();
```

#### Proxy chaining

[](#proxy-chaining)

The `Server` is responsible for creating connections to the target host.

```
Client -> SocksServer -> TargetHost

```

Sometimes it may be required to establish outgoing connections via another SOCKS server. For example, this can be useful if your target SOCKS server requires authentication, but your client does not support sending authentication information (e.g. like most webbrowser).

```
Client -> MiddlemanSocksServer -> TargetSocksServer -> TargetHost

```

The `Server` uses any instance of the `ConnectorInterface` to establish outgoing connections. In order to connect through another SOCKS server, you can simply use a SOCKS connector from the following SOCKS client package:

```
$ composer require clue/socks-react:^0.7
```

You can now create a SOCKS `Client` instance like this:

```
// set next SOCKS server localhost:$targetPort as target
$connector = new React\Socket\TcpConnector($loop);
$client = new Clue\React\Socks\Client('user:pass@127.0.0.1:' . $targetPort, $connector);

// listen on localhost:$middlemanPort
$socket = new Socket($loop);
$socket->listen($middlemanPort, 'localhost');

// start a new server which forwards all connections to the other SOCKS server
$server = new Server($loop, $socket, $client);
```

See also the [example #11](examples).

Proxy chaining can happen on the server side and/or the client side:

- If you ask your client to chain through multiple proxies, then each proxy server does not really know anything about chaining at all. This means that this is a client-only property and not part of this project. For example, you can find this in the companion SOCKS client side project [clue/socks-react](https://github.com/clue/php-socks-react#proxy-chaining).
- If you ask your server to chain through another proxy, then your client does not really know anything about chaining at all. This means that this is a server-only property and can be implemented as above.

Install
-------

[](#install)

The recommended way to install this library is [through Composer](http://getcomposer.org). [New to Composer?](http://getcomposer.org/doc/00-intro.md)

This will install the latest supported version:

```
$ composer require clue/socks-server:^0.7
```

See also the [CHANGELOG](CHANGELOG.md) for details about version upgrades.

Tests
-----

[](#tests)

To run the test suite, you first need to clone this repo and then install all dependencies [through Composer](http://getcomposer.org):

```
$ composer install
```

To run the test suite, go to the project root and run:

```
$ php vendor/bin/phpunit
```

License
-------

[](#license)

MIT, see LICENSE

More
----

[](#more)

- If you're looking for an end-user SOCKS server daemon, you may want to use [clue/psocksd](https://github.com/clue/psocksd).
- If you're looking for a SOCKS client implementation, consider using [clue/socks-react](https://github.com/clue/php-socks-react).

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 99.6% 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 ~79 days

Total

3

Last Release

3318d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/776829?v=4)[Christian Lück](/maintainers/clue)[@clue](https://github.com/clue)

---

Top Contributors

[![clue](https://avatars.githubusercontent.com/u/776829?v=4)](https://github.com/clue "clue (263 commits)")[![sinacek](https://avatars.githubusercontent.com/u/1140123?v=4)](https://github.com/sinacek "sinacek (1 commits)")

---

Tags

asyncreactphpsocks clientsocks servertcp tunnelsocks protocol

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/clue-socks-server/health.svg)

```
[![Health](https://phpackages.com/badges/clue-socks-server/health.svg)](https://phpackages.com/packages/clue-socks-server)
```

###  Alternatives

[react/socket

Async, streaming plaintext TCP/IP and secure TLS socket server and client connections for ReactPHP

1.3k116.9M402](/packages/react-socket)[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.

1171.1M33](/packages/clue-socks-react)[clue/docker-react

Async, event-driven access to the Docker Engine API, built on top of ReactPHP.

113154.9k1](/packages/clue-docker-react)[react/async

Async utilities and fibers for ReactPHP

2238.8M171](/packages/react-async)[clue/reactphp-eventsource

Instant real-time updates. Lightweight EventSource client receiving live messages via HTML5 Server-Sent Events (SSE). Fast stream processing built on top of ReactPHP's event-driven architecture.

5818.5k3](/packages/clue-reactphp-eventsource)[clue/socks

Async SOCKS proxy client and server (SOCKS4, SOCKS4a and SOCKS5)

611.0k](/packages/clue-socks)

PHPackages © 2026

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