File tree Expand file tree Collapse file tree 9 files changed +112
-8
lines changed Expand file tree Collapse file tree 9 files changed +112
-8
lines changed Original file line number Diff line number Diff line change @@ -225,7 +225,7 @@ $browser->get('https://example.com/')->then(function (Psr\Http\Message\ResponseI
225225});
226226```
227227
228- See also [ ReactPHP's HTTP client] ( https://github.com/reactphp/http#client-usage ) for more details.
228+ See also [ ReactPHP's HTTP client] ( https://github.com/reactphp/http#client-usage ) and any of the [ examples ] ( examples ) for more details.
229229
230230#### Connection timeout
231231
Original file line number Diff line number Diff line change 2525 "require-dev" : {
2626 "phpunit/phpunit" : " ^9.0 || ^7.0 || ^5.0 || ^4.8" ,
2727 "react/event-loop" : " ^1.0 || ^0.5 || ^0.4 || ^0.3" ,
28+ "react/http" : " ^1.0" ,
2829 "clue/block-react" : " ^1.1"
2930 }
3031}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ // A simple example which uses an HTTP client to request https://example.com/ through an HTTP CONNECT proxy.
4+ // You can use any kind of proxy, for example https://github.com/leproxy/leproxy and execute it like this:
5+ //
6+ // $ php leproxy-latest.php
7+ //
8+ // To run the example, go to the project root and run:
9+ //
10+ // $ php examples/01-http-requests.php
11+ //
12+ // The proxy can be given as first argument and defaults to localhost:8080 otherwise.
13+ use React \HTTP \Browser ;
14+
15+ require __DIR__ . '/../vendor/autoload.php ' ;
16+
17+ $ url = isset ($ argv [1 ]) ? $ argv [1 ] : '127.0.0.1:8080 ' ;
18+
19+ $ loop = React \EventLoop \Factory::create ();
20+ $ proxy = new Clue \React \HttpProxy \ProxyConnector ($ url , new React \Socket \Connector ($ loop ));
21+
22+ $ connector = new React \Socket \Connector ($ loop , array (
23+ 'tcp ' => $ proxy ,
24+ 'dns ' => false
25+ ));
26+
27+ $ browser = new React \Http \Browser ($ loop , $ connector );
28+
29+ $ browser ->get ('https://example.com/ ' )->then (function (Psr \Http \Message \ResponseInterface $ response ) {
30+ var_dump ($ response ->getHeaders (), (string ) $ response ->getBody ());
31+ }, 'printf ' );
32+
33+ $ loop ->run ();
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ // A simple example which uses an HTTP client to request https://example.com/ (optional: Through an HTTP CONNECT proxy.)
4+ // To run the example, go to the project root and run:
5+ //
6+ // $ php examples/02-optional-proxy-http-request.php
7+ //
8+ // To run the same example with your proxy, the proxy URL can be given as an environment variable:
9+ //
10+ // $ http_proxy=127.0.0.1.8181 php examples/02-optional-proxy-http-request.php
11+
12+ require __DIR__ . '/../vendor/autoload.php ' ;
13+
14+ $ loop = React \EventLoop \Factory::create ();
15+
16+ $ connector = null ;
17+ $ url = getenv ('http_proxy ' );
18+ if ($ url !== false ) {
19+ $ connector = new React \Socket \Connector ($ loop );
20+ $ proxy = new Clue \React \HttpProxy \ProxyConnector ($ url , $ connector );
21+ $ connector = new React \Socket \Connector ($ loop , array (
22+ 'tcp ' => $ proxy ,
23+ 'timeout ' => 3.0 ,
24+ 'dns ' => false
25+ ));
26+ }
27+
28+ $ browser = new React \Http \Browser ($ loop , $ connector );
29+
30+ $ browser ->get ('https://example.com/ ' )->then (function (Psr \Http \Message \ResponseInterface $ response ) {
31+ var_dump ($ response ->getHeaders (), (string ) $ response ->getBody ());
32+ }, 'printf ' );
33+
34+ $ loop ->run ();
Original file line number Diff line number Diff line change 11<?php
22
33// A simple example which requests https://google.com/ through an HTTP CONNECT proxy.
4+ // You can use any kind of proxy, for example https://github.com/leproxy/leproxy and execute it like this:
5+ //
6+ // $ php leproxy-latest.php
7+ //
8+ // To run the example, go to the project root and run:
9+ //
10+ // $ php examples/11-proxy-raw-https-protocol.php
11+ //
412// The proxy can be given as first argument and defaults to localhost:8080 otherwise.
513//
614// For illustration purposes only. If you want to send HTTP requests in a real
7- // world project, take a look at https://github.com/clue/ reactphp-buzz# http-proxy
15+ // world project, take a look at example #01 and https://github.com/reactphp/ http#client-usage.
816
917use Clue \React \HttpProxy \ProxyConnector ;
1018use React \Socket \Connector ;
Original file line number Diff line number Diff line change 22
33// A simple example which requests https://google.com/ either directly or through
44// an HTTP CONNECT proxy.
5+ // To run the example, go to the project root and run:
6+ //
7+ // $ php examples/12-optional-proxy-raw-https-protocol.php
8+ //
59// The Proxy can be given as first argument or does not use a proxy otherwise.
610// This example highlights how changing from direct connection to using a proxy
711// actually adds very little complexity and does not mess with your actual
812// network protocol otherwise.
913//
1014// 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
15+ // world project, take a look at example #01 and https://github.com/reactphp/ http#client-usage.
1216
1317use Clue \React \HttpProxy \ProxyConnector ;
1418use React \Socket \Connector ;
Original file line number Diff line number Diff line change 11<?php
22
33// A simple example which requests https://google.com/ through an HTTP CONNECT proxy.
4+ // You can use any kind of proxy, for example https://github.com/leproxy/leproxy and execute it like this:
5+ //
6+ // $ php leproxy-latest.php
7+ //
8+ // To run the example, go to the project root and run:
9+ //
10+ // $ php examples/13-custom-proxy-headers.php
11+ //
412// The proxy can be given as first argument and defaults to localhost:8080 otherwise.
513//
614// For illustration purposes only. If you want to send HTTP requests in a real
7- // world project, take a look at https://github.com/clue/ reactphp-buzz# http-proxy
15+ // world project, take a look at example #01 and https://github.com/reactphp/ http#client-usage.
816
917use Clue \React \HttpProxy \ProxyConnector ;
1018use React \Socket \Connector ;
Original file line number Diff line number Diff line change 11<?php
22
3- // A simple example which uses a plain SMTP connection to Googlemail through a HTTP CONNECT proxy.
4- // Proxy can be given as first argument and defaults to localhost:8080 otherwise.
3+ // A simple example which requests https://google.com/ through an HTTP CONNECT proxy.
4+ // You can use any kind of proxy, for example https://github.com/leproxy/leproxy and execute it like this:
5+ //
6+ // $ php leproxy-latest.php
7+ //
8+ // To run the example, go to the project root and run:
9+ //
10+ // $ php examples/21-proxy-raw-smtp-protocol.php
11+ //
12+ // The proxy can be given as first argument and defaults to localhost:8080 otherwise.
513// Please note that MANY public proxies do not allow SMTP connections, YMMV.
614
715use Clue \React \HttpProxy \ProxyConnector ;
Original file line number Diff line number Diff line change 11<?php
22
3- // A simple example which uses a secure SMTP connection to Googlemail through a HTTP CONNECT proxy.
4- // Proxy can be given as first argument and defaults to localhost:8080 otherwise.
3+ // A simple example which requests https://google.com/ through an HTTP CONNECT proxy.
4+ // You can use any kind of proxy, for example https://github.com/leproxy/leproxy and execute it like this:
5+ //
6+ // $ php leproxy-latest.php
7+ //
8+ // To run the example, go to the project root and run:
9+ //
10+ // $ php examples/22-proxy-raw-smtps-protocol.php
11+ //
12+ // The proxy can be given as first argument and defaults to localhost:8080 otherwise.
513// This example highlights how changing from plain connections (see previous
614// example) to using a secure connection actually adds very little complexity
715// and does not mess with your actual network protocol otherwise.
You can’t perform that action at this time.
0 commit comments