|
1 | 1 | <?php
|
2 | 2 |
|
3 |
| -// A simple example which requests https://google.com/ either directly or through |
4 |
| -// an HTTP CONNECT proxy. |
5 |
| -// The Proxy can be given as first argument or does not use a proxy otherwise. |
| 3 | +// A simple example which requests https://google.com/ directly (optional: Through an HTTP CONNECT proxy.) |
| 4 | +// To run the example, go to the project root and run: |
| 5 | +// |
| 6 | +// $ php examples/12-optional-proxy-raw-https-protocol.php |
| 7 | +// |
| 8 | +// If you chose the optional route, you can use any kind of proxy, for example https://github.com/leproxy/leproxy and execute it like this: |
| 9 | +// |
| 10 | +// $ php leproxy.php |
| 11 | +// |
| 12 | +// To run the same example with your proxy, the proxy URL can be given as an environment variable: |
| 13 | +// |
| 14 | +// $ http_proxy=127.0.0.2:8080 php examples/12-optional-proxy-raw-https-protocol.php |
| 15 | +// |
6 | 16 | // This example highlights how changing from direct connection to using a proxy
|
7 | 17 | // actually adds very little complexity and does not mess with your actual
|
8 | 18 | // network protocol otherwise.
|
9 | 19 | //
|
10 | 20 | // For illustration purposes only. If you want to send HTTP requests in a real
|
11 |
| -// world project, take a look at https://github.com/clue/reactphp-buzz#http-proxy |
| 21 | +// world project, take a look at example #01, example #02 and https://github.com/reactphp/http#client-usage. |
12 | 22 |
|
13 | 23 | use Clue\React\HttpProxy\ProxyConnector;
|
14 | 24 | use React\Socket\Connector;
|
|
20 | 30 |
|
21 | 31 | $connector = new Connector($loop);
|
22 | 32 |
|
23 |
| -// first argument given? use this as the proxy URL |
24 |
| -if (isset($argv[1])) { |
25 |
| - $proxy = new ProxyConnector($argv[1], $connector); |
| 33 | +$url = getenv('http_proxy'); |
| 34 | +if ($url !== false) { |
| 35 | + $proxy = new ProxyConnector($url, $connector); |
26 | 36 | $connector = new Connector($loop, array(
|
27 | 37 | 'tcp' => $proxy,
|
28 | 38 | 'timeout' => 3.0,
|
|
0 commit comments