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