Skip to content

Commit 4ee8fee

Browse files
committed
Clean up examples
1 parent eddf0b6 commit 4ee8fee

6 files changed

+47
-15
lines changed

examples/01-http-request.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,21 @@
55
//
66
// $ php leproxy-latest.php
77
//
8-
// To run the example, go to the project root and run:
8+
// To run the example (The proxy deafults to localhost:8080), go to the project root and run:
99
//
1010
// $ php examples/01-http-requests.php
1111
//
12-
// The proxy can be given as first argument and defaults to localhost:8080 otherwise.
12+
// If you want to run the same example with any other proxy URL , just use:
13+
//
14+
// $ http_proxy=127.0.0.1.8181 php examples/01-http-requests.php
1315
use React\HTTP\Browser;
1416

1517
require __DIR__ . '/../vendor/autoload.php';
1618

17-
$url = isset($argv[1]) ? $argv[1] : '127.0.0.1:8080';
19+
$url = getenv('http_proxy');
20+
if($url === false){
21+
$url = '127.0.0.1:8080';
22+
}
1823

1924
$loop = React\EventLoop\Factory::create();
2025
$proxy = new Clue\React\HttpProxy\ProxyConnector($url, new React\Socket\Connector($loop));

examples/11-proxy-raw-https-protocol.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
//
1010
// $ php examples/11-proxy-raw-https-protocol.php
1111
//
12-
// The proxy can be given as first argument and defaults to localhost:8080 otherwise.
12+
// If you want to run the same example with any other proxy URL , just use:
13+
//
14+
// $ http_proxy=127.0.0.1.8181 php examples/11-proxy-raw-https-protocol.php
1315
//
1416
// For illustration purposes only. If you want to send HTTP requests in a real
1517
// world project, take a look at example #01 and https://github.com/reactphp/http#client-usage.
@@ -20,7 +22,10 @@
2022

2123
require __DIR__ . '/../vendor/autoload.php';
2224

23-
$url = isset($argv[1]) ? $argv[1] : '127.0.0.1:8080';
25+
$url = getenv('http_proxy');
26+
if($url === false){
27+
$url = '127.0.0.1:8080';
28+
}
2429

2530
$loop = React\EventLoop\Factory::create();
2631

examples/12-optional-proxy-raw-https-protocol.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
//
77
// $ php examples/12-optional-proxy-raw-https-protocol.php
88
//
9-
// The Proxy can be given as first argument or does not use a proxy otherwise.
9+
// If you want to run the same example with your proxy, just use:
10+
//
11+
// $ http_proxy=127.0.0.1.8181 php examples/12-optional-proxy-raw-https-protocol.php
12+
//
13+
// The proxy URL can be given as an environment variable
1014
// This example highlights how changing from direct connection to using a proxy
1115
// actually adds very little complexity and does not mess with your actual
1216
// network protocol otherwise.
@@ -24,9 +28,10 @@
2428

2529
$connector = new Connector($loop);
2630

27-
// first argument given? use this as the proxy URL
28-
if (isset($argv[1])) {
29-
$proxy = new ProxyConnector($argv[1], $connector);
31+
//Define environment variable with your proxy URL
32+
$url = getenv('http_proxy');
33+
if ($url!== false) {
34+
$proxy = new ProxyConnector($url, $connector);
3035
$connector = new Connector($loop, array(
3136
'tcp' => $proxy,
3237
'timeout' => 3.0,

examples/13-custom-proxy-headers.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
//
1010
// $ php examples/13-custom-proxy-headers.php
1111
//
12-
// The proxy can be given as first argument and defaults to localhost:8080 otherwise.
12+
// If you want to run the same example with any other proxy URL , just use:
13+
//
14+
// $ http_proxy=127.0.0.1.8181 php examples/13-custom-proxy-headers.php
1315
//
1416
// For illustration purposes only. If you want to send HTTP requests in a real
1517
// world project, take a look at example #01 and https://github.com/reactphp/http#client-usage.
@@ -20,7 +22,10 @@
2022

2123
require __DIR__ . '/../vendor/autoload.php';
2224

23-
$url = isset($argv[1]) ? $argv[1] : '127.0.0.1:8080';
25+
$url = getenv('http_proxy');
26+
if($url === false){
27+
$url = '127.0.0.1:8080';
28+
}
2429

2530
$loop = React\EventLoop\Factory::create();
2631

examples/21-proxy-raw-smtp-protocol.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
//
1010
// $ php examples/21-proxy-raw-smtp-protocol.php
1111
//
12-
// The proxy can be given as first argument and defaults to localhost:8080 otherwise.
12+
// If you want to run the same example with any other proxy URL , just use:
13+
//
14+
// $ http_proxy=127.0.0.1.8181 php examples/21-proxy-raw-smtp-protocol.php
15+
1316
// Please note that MANY public proxies do not allow SMTP connections, YMMV.
1417

1518
use Clue\React\HttpProxy\ProxyConnector;
@@ -18,7 +21,10 @@
1821

1922
require __DIR__ . '/../vendor/autoload.php';
2023

21-
$url = isset($argv[1]) ? $argv[1] : '127.0.0.1:8080';
24+
$url = getenv('http_proxy');
25+
if($url === false){
26+
$url = '127.0.0.1:8080';
27+
}
2228

2329
$loop = React\EventLoop\Factory::create();
2430

examples/22-proxy-raw-smtps-protocol.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
//
1010
// $ php examples/22-proxy-raw-smtps-protocol.php
1111
//
12-
// The proxy can be given as first argument and defaults to localhost:8080 otherwise.
12+
// If you want to run the same example with any other proxy URL , just use:
13+
//
14+
// $ http_proxy=127.0.0.1.8181 php examples/22-proxy-raw-smtps-protocol.php
15+
1316
// This example highlights how changing from plain connections (see previous
1417
// example) to using a secure connection actually adds very little complexity
1518
// and does not mess with your actual network protocol otherwise.
@@ -21,7 +24,10 @@
2124

2225
require __DIR__ . '/../vendor/autoload.php';
2326

24-
$url = isset($argv[1]) ? $argv[1] : '127.0.0.1:8080';
27+
$url = getenv('http_proxy');
28+
if($url === false){
29+
$url = '127.0.0.1:8080';
30+
}
2531

2632
$loop = React\EventLoop\Factory::create();
2733

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy