PHP code example of clue / socks

1. Go to this page and download the library: Download clue/socks library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

clue / socks example snippets



p = React\EventLoop\Factory::create();

// use google's dns servers
$dnsResolverFactory = new React\Dns\Resolver\Factory();
$dns = $dnsResolverFactory->createCached('8.8.8.8', $loop);

// create SOCKS client which communicates with SOCKS server 127.0.0.1:9050
$factory = new Socks\Factory($loop, $dns);
$client = $factory->createClient('127.0.0.1', 9050);

// now work with your $client, see below

$loop->run();

$tcp = $client->createConnector();

$tcp->create('www.google.com',80)->then(function (React\Stream\Stream $stream) {
    echo 'connected to www.google.com:80';
    $stream->write("GET / HTTP/1.0\r\n\r\n");
    // ...
});

$httpclient = $client->createHttpClient();

$request = $httpclient->request('GET', 'https://www.google.com/', array('user-agent'=>'Custom/1.0'));
$request->on('response', function (React\HttpClient\Response $response) {
    var_dump('Headers received:', $response->getHeaders());
    
    // dump whole response body
    $response->on('data', function ($data) {
        echo $data;
    });
});
$request->end();

$ssl = $client->createSecureConnector();

// now create an SSL encrypted connection (notice the $ssl instead of $tcp)
$ssl->create('www.google.com',443)->then(function (React\Stream\Stream $stream) {
    // proceed with just the plain text data and everything is encrypted/decrypted automatically
    echo 'connected to SSL encrypted www.google.com';
    $stream->write("GET / HTTP/1.0\r\n\r\n");
    // ...
});

// valid protocol versions:
$client->setProtocolVersion('4a');
$server->setProtocolVersion(5);

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

$client->setResolveLocal(false);

$client->setAuth('username', 'password');

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

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

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

$client = $factory->createClient('127.0.0.1', 9050);


$client = $factory->createClient('127.0.0.1', 9050);
$client->setResolveLocal(false);