public function waitForDownload(Torrent $torrent) { $loop = \React\EventLoop\Factory::create(); $check = function () use($loop, $torrent) { /** * @var Torrent[] $results */ $results = $this->getTransmission()->all(); $found = false; foreach ($results as $result) { if ($result->getHash() === $torrent->getHash()) { $found = true; $torrent = $result; } } if (!$found) { throw new \RuntimeException('Torrent not found?'); } /** @var \Transmission\Model\Torrent $torrent */ if ($torrent->getPercentDone() == "100") { echo " [ download complete ] \n"; $loop->stop(); } else { $eta = number_format($torrent->getEta() / 60, 2); $rate = number_format($torrent->getDownloadRate() / 1024 / 1024, 3); echo " [ progress: " . $torrent->getPercentDone() . "% | rate: " . $rate . "Mb/s | eta: {$eta} min | peers: " . count($torrent->getPeers()) . " | trackers: " . count($torrent->getTrackers()) . "]\n"; } }; $loop->addPeriodicTimer(5, $check); $check(); $loop->run(); return true; }