Web::_curl PHP Method

_curl() protected method

HTTP request via cURL
protected _curl ( $url, $options ) : array
$url string
$options array
return array
    protected function _curl($url, $options)
    {
        $curl = curl_init($url);
        if (!ini_get('open_basedir')) {
            curl_setopt($curl, CURLOPT_FOLLOWLOCATION, $options['follow_location']);
        }
        curl_setopt($curl, CURLOPT_MAXREDIRS, $options['max_redirects']);
        curl_setopt($curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
        curl_setopt($curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $options['method']);
        if (isset($options['header'])) {
            curl_setopt($curl, CURLOPT_HTTPHEADER, $options['header']);
        }
        if (isset($options['content'])) {
            curl_setopt($curl, CURLOPT_POSTFIELDS, $options['content']);
        }
        curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate');
        $timeout = isset($options['timeout']) ? $options['timeout'] : ini_get('default_socket_timeout');
        curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $timeout);
        curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
        $headers = [];
        curl_setopt($curl, CURLOPT_HEADERFUNCTION, function ($curl, $line) use(&$headers) {
            if ($trim = trim($line)) {
                $headers[] = $trim;
            }
            return strlen($line);
        });
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        ob_start();
        curl_exec($curl);
        $err = curl_error($curl);
        curl_close($curl);
        $body = ob_get_clean();
        if (!$err && $options['follow_location'] && preg_match('/^Location: (.+)$/m', implode(PHP_EOL, $headers), $loc)) {
            $options['max_redirects']--;
            if ($loc[1][0] == '/') {
                $parts = parse_url($url);
                $loc[1] = $parts['scheme'] . '://' . $parts['host'] . (isset($parts['port']) && !in_array($parts['port'], [80, 443]) ? ':' . $parts['port'] : '') . $loc[1];
            }
            return $this->request($loc[1], $options);
        }
        return ['body' => $body, 'headers' => $headers, 'engine' => 'cURL', 'cached' => FALSE, 'error' => $err];
    }