47 public static function get($url, $headers = array())
52 $parsedUrl = parse_url($url);
53 $isLocalhost = isset($parsedUrl[
'host']) && (
54 $parsedUrl[
'host'] ===
'localhost' ||
55 $parsedUrl[
'host'] ===
'127.0.0.1' ||
56 $parsedUrl[
'host'] ===
'::1'
60 curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
61 curl_setopt($ch, CURLOPT_RETURNTRANSFER,
true);
62 curl_setopt($ch, CURLOPT_VERBOSE, self::$verbose);
63 curl_setopt($ch, CURLOPT_URL, $url);
67 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
false);
68 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,
false);
70 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
true);
71 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
75 if ($caBundle && file_exists($caBundle)) {
76 curl_setopt($ch, CURLOPT_CAINFO, $caBundle);
82 $allHeaders = array_merge($defaultHeaders, $headers);
83 if (!empty($allHeaders)) {
84 curl_setopt($ch, CURLOPT_HTTPHEADER, $allHeaders);
87 $data = curl_exec($ch);
90 $errorCode = curl_errno($ch);
92 $error = curl_error($ch);
94 Log::error(
'CURL Error (' . $errorType .
'): ' . $error .
' (URL: ' . $url .
')');
99 if (PHP_VERSION_ID < 80000) {
104 if ($error !==
null) {
105 return array(
'data' => trim($data),
'error' => $error,
'error_type' => self::categorizeCurlError($errorCode, $error, $isLocalhost));
108 return array(
'data' => trim($data));
139 $parsedUrl = parse_url($url);
140 $isLocalhost = isset($parsedUrl[
'host']) && (
141 $parsedUrl[
'host'] ===
'localhost' ||
142 $parsedUrl[
'host'] ===
'127.0.0.1' ||
143 $parsedUrl[
'host'] ===
'::1'
147 curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
148 curl_setopt($ch, CURLOPT_RETURNTRANSFER,
true);
149 curl_setopt($ch, CURLOPT_VERBOSE, self::$verbose);
150 curl_setopt($ch, CURLOPT_HEADER,
true);
151 curl_setopt($ch, CURLOPT_NOBODY,
true);
152 curl_setopt($ch, CURLOPT_URL, $url);
156 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
false);
157 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,
false);
159 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
true);
160 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
164 if ($caBundle && file_exists($caBundle)) {
165 curl_setopt($ch, CURLOPT_CAINFO, $caBundle);
171 $allHeaders = array_merge($defaultHeaders, $headers);
172 if (!empty($allHeaders)) {
173 curl_setopt($ch, CURLOPT_HTTPHEADER, $allHeaders);
179 $errorCode = curl_errno($ch);
181 $error = curl_error($ch);
183 Log::error(
'CURL Error getting headers (' . $errorType .
'): ' . $error .
' (URL: ' . $url .
')');
188 if (PHP_VERSION_ID < 80000) {
193 if ($error !==
null) {
194 return array(
'headers' => array(),
'error' => $error,
'error_type' => self::categorizeCurlError($errorCode, $error, $isLocalhost));
198 $parsedHeaders = array();
200 $responseLines = explode(
"\n",
$response);
201 foreach ($responseLines as $line) {
204 $parsedHeaders[] = $line;
209 return array(
'headers' => $parsedHeaders);
274 if (in_array($errorCode, array(
275 CURLE_COULDNT_RESOLVE_HOST,
276 CURLE_COULDNT_CONNECT,
277 CURLE_OPERATION_TIMEOUTED,
285 if (in_array($errorCode, array(
287 CURLE_SSL_PEER_CERTIFICATE,
288 CURLE_SSL_CERTPROBLEM,
290 CURLE_SSL_CONNECT_ERROR,
291 CURLE_SSL_ENGINE_NOTFOUND,
292 CURLE_SSL_ENGINE_SETFAILED
295 return $isLocalhost ?
'self-signed' :
'ssl';