execCreate($container, $cmd)->then(function ($info) use ($client) { $stream = $client->execStartStream($info['Id'], true); $start = microtime(true); $bytes = 0; $stream->on('data', function ($chunk) use (&$bytes) { $bytes += strlen($chunk); }); $stream->on('error', 'printf'); // show stats when stream ends $stream->on('close', function () use ($client, &$bytes, $start) { $time = microtime(true) - $start; echo 'Received ' . $bytes . ' bytes in ' . round($time, 1) . 's => ' . round($bytes / $time / 1000000, 1) . ' MB/s' . PHP_EOL; }); }, 'printf'); $loop->run();