Commit 17e5742e authored by Maxime Veber's avatar Maxime Veber
Browse files

Add test 1

parent 63c86798
Pipeline #621 failed with stages
<?php
require 'vendor/autoload.php';
use React\EventLoop\Factory as EventLoopFactory;
use Symfony\Component\HttpClient\NativeHttpClient;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use React\Promise\Stream;
$loop = EventLoopFactory::create();
$client = new NativeHttpClient();
function load($url, \React\EventLoop\LoopInterface $loop, HttpClientInterface $client) {
// $def = new Deferred();
$response = $client->request('GET', $url);
$stream = new \React\Stream\ReadableResourceStream($response->toStream(), $loop);
return $stream;
// $loop->addReadStream($response->toStream(), function ($stream) use ($def) {
//// var_dump(stream_get_meta_data($stream));
// echo "HELO\n";
// $def->resolve();
// });
// return Stream\unwrapReadable(Stream\buffer($stream));
// return $def->promise();
}
//load('https://cdimage.debian.org/debian-cd/current-live/amd64/iso-hybrid/debian-live-10.2.0-amd64-cinnamon.iso', $loop, $client)
// ->on('pipe', function () {
// echo "hello.";
// })
// ->on('end', function () {
// echo "Loaded cinnamon\n";
// });
//
//load('https://cdimage.debian.org/debian-cd/current-live/amd64/iso-hybrid/debian-live-10.2.0-amd64-standard.iso', $loop, $client)
// ->on('data', function () {
// echo "world.";
// })
// ->on('end', function () {
// echo "Loaded standard\n";
// });
load('http://localhost:8000/long-to-execute', $loop, $client)
->on('data', function ($data) {
echo "hello.";
var_dump($data);
})
->on('end', function () {
echo "Loaded long\n";
});
load('http://localhost:8001/faster', $loop, $client)
->on('data', function ($data) {
echo "world.";
var_dump($data);
})
->on('end', function () {
echo "Loaded fast\n";
});
echo "Not blocking at this state\n";
$loop->run();
//$response = $client->request('GET', 'https://cdimage.debian.org/debian-cd/current-live/amd64/iso-hybrid/debian-live-10.2.0-amd64-standard.iso');
//$streamResource = $response->toStream();
//
//file_put_contents('foo.iso', stream_get_contents($streamResource));
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment