File tree Expand file tree Collapse file tree 7 files changed +42
-7
lines changed
Expand file tree Collapse file tree 7 files changed +42
-7
lines changed 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 excecute it like this:
5+ // $ php leproxy-latest.php
6+ // The proxy can be given as first argument and defaults to localhost:8080 otherwise.
7+
8+ use React \HTTP \Browser ;
9+
10+ require __DIR__ . '/../vendor/autoload.php ' ;
11+
12+ $ loop = React \EventLoop \Factory::create ();
13+ $ proxy = new Clue \React \HttpProxy \ProxyConnector ('127.0.0.1:8080 ' , new React \Socket \Connector ($ loop ));
14+
15+ $ connector = new React \Socket \Connector ($ loop , array (
16+ 'tcp ' => $ proxy ,
17+ 'dns ' => false
18+ ));
19+
20+ $ browser = new React \Http \Browser ($ loop , $ connector );
21+
22+ $ browser ->get ('https://example.com/ ' )->then (function (Psr \Http \Message \ResponseInterface $ response ) {
23+ var_dump ($ response ->getHeaders (), (string ) $ response ->getBody ());
24+ }, 'printf ' );
25+
26+ $ 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 excecute it like this:
5+ // $ php leproxy-latest.php
46// The proxy can be given as first argument and defaults to localhost:8080 otherwise.
57//
68// 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
9+ // world project, take a look at example-01
810
911use Clue \React \HttpProxy \ProxyConnector ;
1012use React \Socket \Connector ;
Original file line number Diff line number Diff line change 88// network protocol otherwise.
99//
1010// 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
11+ // world project, take a look at example-01
1212
1313use Clue \React \HttpProxy \ProxyConnector ;
1414use 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 excecute it like this:
5+ // $ php leproxy-latest.php
46// The proxy can be given as first argument and defaults to localhost:8080 otherwise.
57//
68// 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
9+ // world project, take a look at example-01
810
911use Clue \React \HttpProxy \ProxyConnector ;
1012use 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 excecute it like this:
5+ // $ php leproxy-latest.php
6+ // The proxy can be given as first argument and defaults to localhost:8080 otherwise.
57// Please note that MANY public proxies do not allow SMTP connections, YMMV.
68
79use 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 excecute it like this:
5+ // $ php leproxy-latest.php
6+ // The proxy can be given as first argument and defaults to localhost:8080 otherwise.
57// This example highlights how changing from plain connections (see previous
68// example) to using a secure connection actually adds very little complexity
79// and does not mess with your actual network protocol otherwise.
You can’t perform that action at this time.
0 commit comments