PHP code example of legionth / http-client-react
1. Go to this page and download the library: Download legionth/http-client-react library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
legionth / http-client-react example snippets
$uri = 'tcp://httpbin.org:80';
$request = new Request('GET', 'http://httpbin.org');
$promise = $client->request($uri, $request);
$promise = $client->request($uri, $request);
$promise->then(
function (\Psr\Http\Message\ResponseInterface $response) {
echo 'Successfully received a response from the server:' . PHP_EOL;
echo RingCentral\Psr7\str($response);
},
function (\Exception $exception) {
echo $exception->getMessage() . PHP_EOL;
}
);
$promise = $client->request($uri, $request);
$promise->then(
function (ResponseInterface $response) {
echo 'Successfully received a response from the server:' . PHP_EOL;
echo RingCentral\Psr7\str($response);
$body = $response->getBody();
$body->on('data', function ($data) {
echo "Body-Data: " . $data . PHP_EOL;
});
$body->on('end', function () {
exit(0);
});
},
function (\Exception $exception) {
echo $exception->getMessage() . PHP_EOL;
}
);
$stream = new ReadableStream();
$timer = $loop->addPeriodicTimer(0.5, function () use ($stream) {
$stream->emit('data', array(microtime(true) . PHP_EOL));
});
$loop->addTimer(5, function() use ($loop, $timer, $stream) {
$loop->cancelTimer($timer);
$stream->emit('end');
});
$request = new Request(
'POST',
'http://127.0.0.1:10000',
array(
'Host' => '127.0.0.1',
'Content-Type' => 'text/plain'
),
$stream
);
$promise = $client->request($uri, $request);