echo " Total Size: " . Util::formatSize($torrent->getTotalSize()) . "\n"; $download = new Download($torrent, $dir); $download->on('allocate', function ($finished, $total) { $p = (int) ($finished / $total * 100.0); echo "Allocating Files ... ({$p}%) \r"; }); $download->on('check', function ($finished, $total) { $p = (int) ($finished / $total * 100.0); echo "Checking Files ... ({$p}%) \r"; }); $download->start(); echo "Starting download ... \r"; $lastTotal = 0; $lastTime = time(); $downloadSpeed = '0K/s'; while (!$download->isComplete()) { $download->tick(); $p = $download->getProgress(); $x = $download->getConnectedPeerCount(); $y = $download->getPeerCount(); $now = time(); $span = $now - $lastTime; if ($span > 0) { $lastTime = $now; $total = $download->getDownloaded(); $delta = $total - $lastTotal; $lastTotal = $total; $downloadSpeed = Util::formatSize($delta) . '/s'; } echo "Downloading ... ({$p}%) ({$x}/{$y} peers) ({$downloadSpeed}) \r"; //sleep(1);