diff --git a/examples/01-http-request.php b/examples/01-http-request.php index a7cedec..45b9894 100644 --- a/examples/01-http-request.php +++ b/examples/01-http-request.php @@ -5,16 +5,20 @@ // // $ php leproxy-latest.php // -// To run the example, go to the project root and run: +// To run the example (The proxy deafults to localhost:8080), go to the project root and run: // // $ php examples/01-http-requests.php // -// The proxy can be given as first argument and defaults to localhost:8080 otherwise. -use React\HTTP\Browser; +// If you want to run the same example with any other proxy URL, just use: +// +// $ http_proxy=127.0.0.1.8181 php examples/01-http-requests.php require __DIR__ . '/../vendor/autoload.php'; -$url = isset($argv[1]) ? $argv[1] : '127.0.0.1:8080'; +$url = getenv('http_proxy'); +if ($url === false) { + $url = '127.0.0.1:8080'; +} $loop = React\EventLoop\Factory::create(); $proxy = new Clue\React\HttpProxy\ProxyConnector($url, new React\Socket\Connector($loop)); diff --git a/examples/11-proxy-raw-https-protocol.php b/examples/11-proxy-raw-https-protocol.php index 36969dd..d46ab69 100644 --- a/examples/11-proxy-raw-https-protocol.php +++ b/examples/11-proxy-raw-https-protocol.php @@ -9,7 +9,9 @@ // // $ php examples/11-proxy-raw-https-protocol.php // -// The proxy can be given as first argument and defaults to localhost:8080 otherwise. +// If you want to run the same example with any other proxy URL, just use: +// +// $ http_proxy=127.0.0.1.8181 php examples/11-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 and https://github.com/reactphp/http#client-usage. @@ -20,7 +22,10 @@ require __DIR__ . '/../vendor/autoload.php'; -$url = isset($argv[1]) ? $argv[1] : '127.0.0.1:8080'; +$url = getenv('http_proxy'); +if ($url === false) { + $url = '127.0.0.1:8080'; +} $loop = React\EventLoop\Factory::create(); diff --git a/examples/12-optional-proxy-raw-https-protocol.php b/examples/12-optional-proxy-raw-https-protocol.php index 690b68d..ccddfab 100644 --- a/examples/12-optional-proxy-raw-https-protocol.php +++ b/examples/12-optional-proxy-raw-https-protocol.php @@ -6,7 +6,10 @@ // // $ php examples/12-optional-proxy-raw-https-protocol.php // -// The Proxy can be given as first argument or does not use a proxy otherwise. +// To run the same example with your proxy, the proxy URL can be given as an environment variable: +// +// $ http_proxy=127.0.0.1.8181 php examples/12-optional-proxy-raw-https-protocol.php +// // This example highlights how changing from direct connection to using a proxy // actually adds very little complexity and does not mess with your actual // network protocol otherwise. @@ -24,9 +27,9 @@ $connector = new Connector($loop); -// first argument given? use this as the proxy URL -if (isset($argv[1])) { - $proxy = new ProxyConnector($argv[1], $connector); +$url = getenv('http_proxy'); +if ($url !== false) { + $proxy = new ProxyConnector($url, $connector); $connector = new Connector($loop, array( 'tcp' => $proxy, 'timeout' => 3.0, diff --git a/examples/13-custom-proxy-headers.php b/examples/13-custom-proxy-headers.php index 7c0b866..d48ab7c 100644 --- a/examples/13-custom-proxy-headers.php +++ b/examples/13-custom-proxy-headers.php @@ -9,7 +9,9 @@ // // $ php examples/13-custom-proxy-headers.php // -// The proxy can be given as first argument and defaults to localhost:8080 otherwise. +// If you want to run the same example with any other proxy URL, just use: +// +// $ http_proxy=127.0.0.1.8181 php examples/13-custom-proxy-headers.php // // For illustration purposes only. If you want to send HTTP requests in a real // world project, take a look at example #01 and https://github.com/reactphp/http#client-usage. @@ -20,7 +22,10 @@ require __DIR__ . '/../vendor/autoload.php'; -$url = isset($argv[1]) ? $argv[1] : '127.0.0.1:8080'; +$url = getenv('http_proxy'); +if ($url === false) { + $url = '127.0.0.1:8080'; +} $loop = React\EventLoop\Factory::create(); diff --git a/examples/21-proxy-raw-smtp-protocol.php b/examples/21-proxy-raw-smtp-protocol.php index de407a0..8b771de 100644 --- a/examples/21-proxy-raw-smtp-protocol.php +++ b/examples/21-proxy-raw-smtp-protocol.php @@ -9,7 +9,10 @@ // // $ php examples/21-proxy-raw-smtp-protocol.php // -// The proxy can be given as first argument and defaults to localhost:8080 otherwise. +// If you want to run the same example with any other proxy URL, just use: +// +// $ http_proxy=127.0.0.1.8181 php examples/21-proxy-raw-smtp-protocol.php +// // Please note that MANY public proxies do not allow SMTP connections, YMMV. use Clue\React\HttpProxy\ProxyConnector; @@ -18,7 +21,10 @@ require __DIR__ . '/../vendor/autoload.php'; -$url = isset($argv[1]) ? $argv[1] : '127.0.0.1:8080'; +$url = getenv('http_proxy'); +if ($url === false) { + $url = '127.0.0.1:8080'; +} $loop = React\EventLoop\Factory::create(); diff --git a/examples/22-proxy-raw-smtps-protocol.php b/examples/22-proxy-raw-smtps-protocol.php index f889517..aceb842 100644 --- a/examples/22-proxy-raw-smtps-protocol.php +++ b/examples/22-proxy-raw-smtps-protocol.php @@ -9,7 +9,10 @@ // // $ php examples/22-proxy-raw-smtps-protocol.php // -// The proxy can be given as first argument and defaults to localhost:8080 otherwise. +// If you want to run the same example with any other proxy URL, just use: +// +// $ http_proxy=127.0.0.1.8181 php examples/22-proxy-raw-smtps-protocol.php +// // This example highlights how changing from plain connections (see previous // example) to using a secure connection actually adds very little complexity // and does not mess with your actual network protocol otherwise. @@ -21,7 +24,10 @@ require __DIR__ . '/../vendor/autoload.php'; -$url = isset($argv[1]) ? $argv[1] : '127.0.0.1:8080'; +$url = getenv('http_proxy'); +if ($url === false) { + $url = '127.0.0.1:8080'; +} $loop = React\EventLoop\Factory::create();