/** * Downloads the given url to the given destination. Tries to resume download if file already exists. * * @param array[File] destination * @param float $chunkSizeMegaBytes * @return boolean|null */ public function download(array $downloadFiles) { $parallel = new CurlParallel(); $parallelCurls = []; foreach ($downloadFiles as &$downloadFile) { /* @var $downloadFile File */ try { $this->setCurlForFile($downloadFile); if ($downloadFile->getCurl()) { $parallel->add($downloadFile->getCurl()); $parallelCurls[] = $downloadFile; } } catch (Exception $ex) { $this->logMessage($ex->getMessage()); } } if (count($parallelCurls) > 0) { $parallel->execute(); foreach ($parallelCurls as $downloadFile) { if ($downloadFile->getCurl() instanceof Curl) { $downloadFile->getCurl()->close(); if (is_resource($downloadFile->getCurl()->options->FILE)) { fclose($downloadFile->getCurl()->options->FILE); } if (!$downloadFile->getCurl()->isSuccessful()) { $this->logMessage("{$downloadFile->getUrl()} Failed to download properly."); } } } } $result = true; foreach ($parallelCurls as $downloadFile) { $newFileSize = $this->_getLocalFileSize($downloadFile->getDestination()); $this->output("Downloaded File Size for {$downloadFile->getUrl()}: {$newFileSize} Bytes"); if ($downloadFile->getInfo()->info->CONTENT_LENGTH_DOWNLOAD == $newFileSize) { $this->logMessage("File Downloaded."); } else { $this->logMessage("File Downloaded, Failed to verify file size."); $result = false; } $this->logMessage(''); } return $result; }
/** * Removes access to {@link Curl::$ch $ch} from a {@link CurlParallel} object. * * @param CurlParallel $multiHandle The CurlParallel object that no longer needs {@link Curl::$ch $ch}. */ public function revoke(CurlParallel $multiHandle) { $multiHandle->release($this->_curlHandle); $this->_isMulti = false; }