[contents] Use file_get_contents when in CLI mode & no certs (#962)
file_get_contents can natively use system root certificates, so use file_get_contents when in CLI mode with no root certificates for cURL.
This commit is contained in:
parent
bb2329fa3a
commit
dc83962483
1 changed files with 78 additions and 61 deletions
|
@ -52,6 +52,21 @@ function getContents($url, $header = array(), $opts = array()){
|
|||
$params = [$url];
|
||||
$cache->setParameters($params);
|
||||
|
||||
// Use file_get_contents if in CLI mode with no root certificates defined
|
||||
if(php_sapi_name() === 'cli' && ini_get('curl.cainfo') === '') {
|
||||
$data = file_get_contents($url);
|
||||
|
||||
if($data === false) {
|
||||
$errorCode = 500;
|
||||
} else {
|
||||
$errorCode = 200;
|
||||
}
|
||||
|
||||
$curlError = '';
|
||||
$curlErrno = '';
|
||||
$headerSize = 0;
|
||||
$finalHeader = array();
|
||||
} else {
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
||||
|
@ -98,6 +113,8 @@ function getContents($url, $header = array(), $opts = array()){
|
|||
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
|
||||
|
||||
$data = curl_exec($ch);
|
||||
$errorCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
|
||||
$curlError = curl_error($ch);
|
||||
$curlErrno = curl_errno($ch);
|
||||
$curlInfo = curl_getinfo($ch);
|
||||
|
@ -108,7 +125,6 @@ function getContents($url, $header = array(), $opts = array()){
|
|||
Debug::log('Cant\'t download ' . $url . ' cUrl error: ' . $curlError . ' (' . $curlErrno . ')');
|
||||
|
||||
$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
|
||||
$errorCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$header = substr($data, 0, $headerSize);
|
||||
|
||||
Debug::log('Response header: ' . $header);
|
||||
|
@ -117,6 +133,7 @@ function getContents($url, $header = array(), $opts = array()){
|
|||
$finalHeader = end($headers);
|
||||
|
||||
curl_close($ch);
|
||||
}
|
||||
|
||||
switch($errorCode) {
|
||||
case 200: // Contents received
|
||||
|
|
Loading…
Reference in a new issue