Skip to content
Snippets Groups Projects
test2.php 996 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);
    
    
    $originalRead = [$stream1, $stream2];
    
    Maxime Veber's avatar
    Maxime Veber committed
    $write = [];
    $except = [];
    do {
    
        $read = $originalRead;
        $foo = @stream_select($read, $write, $except, null, 0);
    
    Maxime Veber's avatar
    Maxime Veber committed
    
        foreach ($read as $item) {
            var_dump(stream_get_contents($item));
        }
    
        echo "Stream 1: \n";
        var_dump(\feof($stream1));
    
        if (\feof($stream1)) {
            unset($originalRead[0]);
        }
    
    Maxime Veber's avatar
    Maxime Veber committed
    
        echo "Stream 2: \n";
        var_dump(\feof($stream2));
    
        if (\feof($stream1)) {
            unset($originalRead[1]);
        }
    } while (!\feof($stream1) || !\feof($stream2)); // while streams are not finished
    
    Maxime Veber's avatar
    Maxime Veber committed