Skip to content

Commit

Permalink
Avoid using curl when it has been disabled, fixes #9423
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Nov 6, 2020
1 parent 4b8e77b commit 3f68999
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/Composer/Command/DiagnoseCommand.php
Expand Up @@ -379,7 +379,11 @@ private function checkVersion($config)

private function getCurlVersion()
{
if (function_exists('curl_version')) {
if (extension_loaded('curl')) {
if (!HttpDownloader::isCurlEnabled()) {
return '<error>disabled via disable_functions, using php streams fallback, which reduces performance</error>';
}

$version = curl_version();

return '<comment>'.$version['version'].'</comment> '.
Expand Down
8 changes: 6 additions & 2 deletions src/Composer/Util/HttpDownloader.php
Expand Up @@ -67,8 +67,7 @@ public function __construct(IOInterface $io, Config $config, array $options = ar
$this->options = array_replace_recursive($this->options, $options);
$this->config = $config;

// TODO enable curl only on 5.6+ if older versions cause any problem
if (extension_loaded('curl')) {
if (self::isCurlEnabled()) {
$this->curl = new Http\CurlDownloader($io, $config, $options, $disableTls);
}

Expand Down Expand Up @@ -423,4 +422,9 @@ private function canUseCurl(array $job)

return true;
}

public static function isCurlEnabled()
{
return \extension_loaded('curl') && \function_exists('curl_multi_exec') && \function_exists('curl_multi_init');
}
}

0 comments on commit 3f68999

Please sign in to comment.