Skip to content
Snippets Groups Projects
test2.php 832 B
Newer Older
  • Learn to ignore specific revisions
  • Maxime Veber's avatar
    Maxime Veber committed
    <?php
    
    use Symfony\Component\HttpClient\NativeHttpClient;
    
    require 'vendor/autoload.php';
    
    $client = new NativeHttpClient();
    $response1 = $client->request('GET', 'http://localhost:8000/long-to-execute');
    $stream1 = $response1->toStream();
    stream_set_blocking($stream1, 0);
    
    $response2 = $response = $client->request('GET', 'http://localhost:8001/faster');
    $stream2 = $response2->toStream();
    stream_set_blocking($stream2, 0);
    
    $write = [];
    $except = [];
    do {
        $read = [$stream1, $stream2];
        $foo = stream_select($read, $write, $except, null, 0);
    
        foreach ($read as $item) {
            var_dump(stream_get_contents($item));
        }
    
        echo "Stream 1: \n";
        var_dump(\feof($stream1));
    
        echo "Stream 2: \n";
        var_dump(\feof($stream2));
    } while (!\feof($stream1) && !\feof($stream2)); // while streams are not finished