From 626370d444f333f817983b342289a8ba89c606c1 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sat, 16 Oct 2021 09:47:04 +0200 Subject: [PATCH] Suggest COMPOSER_DISABLE_NETWORK if a possibly-offline state is detected (#10163) Co-authored-by: Nils Adermann --- src/Composer/Util/Http/CurlDownloader.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Composer/Util/Http/CurlDownloader.php b/src/Composer/Util/Http/CurlDownloader.php index a509d341d..2ecc6e9b6 100644 --- a/src/Composer/Util/Http/CurlDownloader.php +++ b/src/Composer/Util/Http/CurlDownloader.php @@ -305,6 +305,8 @@ class CurlDownloader */ public function tick() { + static $timeoutWarning = false; + if (!$this->jobs) { return; } @@ -343,6 +345,12 @@ class CurlDownloader $error = curl_strerror($errno); } $progress['error_code'] = $errno; + + if ($errno === 28 /* CURLE_OPERATION_TIMEDOUT */ && isset($progress['namelookup_time']) && $progress['namelookup_time'] == 0 && !$timeoutWarning) { + $timeoutWarning = true; + $this->io->writeError('A connection timeout was encountered. If you intend to run Composer without connecting to the internet, run the command again prefixed with COMPOSER_DISABLE_NETWORK=1 to make Composer run in offline mode.'); + } + throw new TransportException('curl error '.$errno.' while downloading '.Url::sanitize($progress['url']).': '.$error); } $statusCode = $progress['http_code'];