loadHTML(file_get_contents($url)); $xpath = new DOMXPath($dom); $list = $xpath->query("//div[@id='mirror_list']//a[text()='HTTP' or text()='FTP']"); foreach($list as $node) { $urls[] = 'http://dev.mysql.com'.$node->getAttribute('href'); } return $urls; } function chooseRandom($urls, $n=10) { shuffle($urls); $urls = array_slice($urls, 0, $n); return $urls; } //try to guess the type of URL $url = $argv[1]; $urls = sourceforge_mirrors($url); if ($urls === FALSE) { $urls = mysql_mirrors($url); } if ($urls === FALSE) { $urls = php_mirrors($url); } if ($urls === FALSE) { die("URL not recognized"); } print_r($urls); $cmd = 'aria2c --file-allocation=prealloc '.implode(' ', chooseRandom($urls)); passthru($cmd); ?>