trigger_error($e); die("ERROR: Failed to parse torrent\n"); } echo " Info Hash: {$torrent->getInfoHashHex()}\n"; echo " Piece Size: " . Util::formatSize($torrent->getPieceSize()) . "\n"; 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;