Beispiel #1
0
<?php

use Clue\React\Buzz\Browser;
use React\Stream\ReadableStreamInterface;
use Psr\Http\Message\ResponseInterface;
use React\Stream\Stream;
use RingCentral\Psr7;
$url = isset($argv[1]) ? $argv[1] : 'http://google.com/';
require __DIR__ . '/../vendor/autoload.php';
$loop = React\EventLoop\Factory::create();
$client = new Browser($loop);
$out = new Stream(STDOUT, $loop);
$out->pause();
$info = new Stream(STDERR, $loop);
$info->pause();
$info->write('Requesting ' . $url . '…' . PHP_EOL);
$client->withOptions(array('streaming' => true))->get($url)->then(function (ResponseInterface $response) use($info, $out) {
    $info->write('Received' . PHP_EOL . Psr7\str($response));
    $response->getBody()->pipe($out);
}, 'printf');
$loop->run();
Beispiel #2
0
 public function testConvertsResponsesToStrings()
 {
     $response = new Psr7\Response(200, array('Baz' => 'bar', 'Qux' => ' ipsum'), 'hello', '1.0', 'FOO');
     $this->assertEquals("HTTP/1.0 200 FOO\r\nBaz: bar\r\nQux: ipsum\r\n\r\nhello", Psr7\str($response));
 }
Beispiel #3
0
<?php

use Clue\React\Buzz\Io\Sender;
use React\SocketClient\TcpConnector;
use React\EventLoop\Factory as LoopFactory;
use Clue\React\Socks\Client as SocksClient;
use Clue\React\Buzz\Browser;
use Psr\Http\Message\ResponseInterface;
use RingCentral\Psr7;
require __DIR__ . '/vendor/autoload.php';
$loop = LoopFactory::create();
// create a new SOCKS client which connects to a SOCKS server listening on localhost:9050
// not already running a SOCKS server? Try this: ssh -D 9050 localhost
$socks = new SocksClient('127.0.0.1:9050', new TcpConnector($loop));
// create a Browser object that uses the SOCKS client for connections
$sender = Sender::createFromLoopConnectors($loop, $socks);
$browser = new Browser($loop, $sender);
// demo fetching HTTP headers (or bail out otherwise)
$browser->get('https://www.google.com/')->then(function (ResponseInterface $response) {
    echo Psr7\str($response);
}, 'printf');
$loop->run();
Beispiel #4
0
<?php

use Clue\React\Buzz\Browser;
use React\Stream\ReadableStreamInterface;
use Psr\Http\Message\ResponseInterface;
use React\Stream\Stream;
use RingCentral\Psr7;
$url = isset($argv[1]) ? $argv[1] : 'https://httpbin.org/post';
require __DIR__ . '/../vendor/autoload.php';
$loop = React\EventLoop\Factory::create();
$client = new Browser($loop);
$in = new Stream(STDIN, $loop);
echo 'Sending STDIN as POST to ' . $url . '…' . PHP_EOL;
$client->post($url, array(), $in)->then(function (ResponseInterface $response) {
    echo 'Received' . PHP_EOL . Psr7\str($response);
}, 'printf');
$loop->run();