Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Maxime Veber
test-sf-http-client
Commits
17e5742e
Commit
17e5742e
authored
Jan 05, 2020
by
Maxime Veber
Browse files
Add test 1
parent
63c86798
Pipeline
#621
failed with stages
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
test1.php
0 → 100644
View file @
17e5742e
<?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));
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment