-
-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy path22-stream-stdin.php
More file actions
27 lines (19 loc) · 731 Bytes
/
22-stream-stdin.php
File metadata and controls
27 lines (19 loc) · 731 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php
use Clue\React\Buzz\Browser;
use Psr\Http\Message\ResponseInterface;
use React\Stream\ReadableResourceStream;
use RingCentral\Psr7;
require __DIR__ . '/../vendor/autoload.php';
if (DIRECTORY_SEPARATOR === '\\') {
fwrite(STDERR, 'Non-blocking console I/O not supported on Windows' . PHP_EOL);
exit(1);
}
$loop = React\EventLoop\Factory::create();
$client = new Browser($loop);
$in = new ReadableResourceStream(STDIN, $loop);
$url = isset($argv[1]) ? $argv[1] : 'https://httpbin.org/post';
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();