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();
$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");
// ...
});