-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
21-proxy-raw-https-protocol.php
34 lines (28 loc) · 1.26 KB
/
21-proxy-raw-https-protocol.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
30
31
32
33
34
<?php
// A simple example which requests https://google.com/ through an SSH proxy server.
// The proxy can be given through the SSH_PROXY env and defaults to localhost otherwise.
//
// You can assign the SSH_PROXY environment and prefix this with a space to make
// sure your login credentials are not stored in your bash history like this:
//
// $ export SSH_PROXY=alice:[email protected]
// $ php examples/21-proxy-raw-https-protocol.php
//
// For illustration purposes only. If you want to send HTTP requests in a real
// world project, take a look at example #01, example #02 and https://github.com/reactphp/http#client-usage.
require __DIR__ . '/../vendor/autoload.php';
$url = getenv('SSH_PROXY') !== false ? getenv('SSH_PROXY') : 'alice@localhost';
$proxy = new Clue\React\SshProxy\SshSocksConnector($url);
$connector = new React\Socket\Connector(array(
'tcp' => $proxy,
'timeout' => 3.0,
'dns' => false
));
$connector->connect('tls://google.com:443')->then(function (React\Socket\ConnectionInterface $connection) {
$connection->write("GET / HTTP/1.1\r\nHost: google.com\r\nConnection: close\r\n\r\n");
$connection->on('data', function ($chunk) {
echo $chunk;
});
}, function (Exception $e) {
echo 'Error: ' . $e->getMessage() . PHP_EOL;
});