From e53370c8c5d94e7e32eec1688532075e98109e55 Mon Sep 17 00:00:00 2001 From: Michael Schmid Date: Thu, 28 Feb 2019 11:05:48 -0600 Subject: [PATCH] #102 Update CurlMulti code with Prefetcher.php from prestissimo --- src/PrestissimoFileFetcher.php | 38 ++++++++++++++++------------------ 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/src/PrestissimoFileFetcher.php b/src/PrestissimoFileFetcher.php index 30b7c23..6fe994d 100644 --- a/src/PrestissimoFileFetcher.php +++ b/src/PrestissimoFileFetcher.php @@ -62,26 +62,24 @@ protected function fetchWithPrestissimo($version, $destination, $override) { $multi = new CurlMulti(); $multi->setRequests($requests); - do { - $multi->setupEventLoop(); - $multi->wait(); - $result = $multi->getFinishedResults(); - $successCnt += $result['successCnt']; - $failureCnt += $result['failureCnt']; - if (isset($result['errors'])) { - $errors += $result['errors']; - } - if ($this->progress) { - foreach ($result['urls'] as $url) { - $this->io->writeError(" - Downloading $successCnt/$totalCnt: $url", TRUE); - } - } - } while ($multi->remain()); - - $urls = array_keys($errors); - if ($urls) { - throw new \Exception('Failed to download ' . implode(", ", $urls)); - } + try { + do { + $multi->setupEventLoop(); + $multi->wait(); + $result = $multi->getFinishedResults(); + $successCnt += $result['successCnt']; + $failureCnt += $result['failureCnt']; + foreach ($result['urls'] as $url) { + if (isset($result['errors'][$url])) { + $this->io->writeError(" - Downloading $successCnt/$totalCnt: $url", TRUE); + } else { + $this->io->writeError(" - Downloading $successCnt/$totalCnt: $url", TRUE); + } + } + } while ($multi->remain()); + } catch (FetchException $e) { + // do nothing + } } }