-
-
Notifications
You must be signed in to change notification settings - Fork 38
/
12-socks-proxy.php
29 lines (22 loc) · 952 Bytes
/
12-socks-proxy.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
use Clue\React\Buzz\Browser;
use Clue\React\Socks\Client as SocksClient;
use Psr\Http\Message\ResponseInterface;
use React\EventLoop\Factory as LoopFactory;
use React\Socket\Connector;
require __DIR__ . '/../vendor/autoload.php';
$loop = LoopFactory::create();
// create a new SOCKS proxy client which connects to a SOCKS proxy server listening on localhost:1080
// not already running a SOCKS proxy server? Try LeProxy.org or this: `ssh -D 1080 localhost`
$proxy = new SocksClient('127.0.0.1:1080', new Connector($loop));
// create a Browser object that uses the SOCKS proxy client for connections
$connector = new Connector($loop, array(
'tcp' => $proxy,
'dns' => false
));
$browser = new Browser($loop, $connector);
// demo fetching HTTP headers (or bail out otherwise)
$browser->get('https://www.google.com/')->then(function (ResponseInterface $response) {
echo RingCentral\Psr7\str($response);
}, 'printf');
$loop->run();