Execute curl, return the result and the http response code

@param $ch
@return array
550002
protected function curlRequest($ch)
	{
		$result = curl_exec($ch);
		$httpStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
		return array($result, $httpStatus);
	}
879065
protected function _init($ch) {
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		try {
			// CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set
			curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
		} catch (\Exception $e) {
		}
		curl_setopt($ch, CURLOPT_HEADER, true);
		curl_setopt($ch, CURLOPT_HTTPGET, true);
		curl_setopt($ch, CURLOPT_ENCODING, "gzip");
		
		// Trust invalid certificate
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

		// add options injected via constructor
		curl_setopt_array($ch, $this->_options);
		
		return $ch;
	}
561498
protected function curl_execute()
    {
        $ch = curl_init();

        curl_setopt_array($ch, $this->getOptions());

        $this->_content = curl_exec($ch);

        $this->_errorCode = curl_errno($ch);

        $this->_info = curl_getinfo($ch);

        if ($this->_errorCode) {
            $this->_errorMessage = curl_error($ch);
        }
        curl_close($ch);
        return $this->isHttpOK();
    }
574948
public function parseHeaders($src)
    {
        $headers = array();

        $codeMatched = false;
        
        // curl request header
        if (!is_array($src)) {
            $src = explode("\n",$src);
        }
                
        foreach ($src as $i) {
            $row = explode(':', $i, 2);
            
            // header with no key/value - HTTP response, get code and status
            if(!isset($row[1])){
                $headers[] = $row[0];

                $matches = array();
                if(!$codeMatched && preg_match('#HTTP/1.[0-1] ([0-9]{3})(.*)#si', $row[0], $matches)){
                    $headers['Code'] = $matches[1];
                    $headers['Status'] = trim($matches[2]);
                    $codeMatched = true;
                }

                continue;
            }

            $key = trim($row[0]);
            $val = trim($row[1]);
            $headers[$key] = $val;
        }
        return $headers;
    }
632301
public function fetch() : array 
    {
        $url = 'https://jsonvat.com/';

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_TIMEOUT, 6);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_MAXREDIRS, 2);
        $body = (string) curl_exec($ch);
        $status = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);

        if ($body === '' || $status >= 400) {
            throw new ClientException( "Error fetching rates from {$url}.");
        }

        return $this->parseResponse($body);

    }
890019
private function execute($content)
	{
		$ch = curl_init();

		curl_setopt($ch, CURLOPT_URL, $this->url);
		curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: Token '.$this->token, 'Content-Type: application/json', 'Accept: application/json']);
		curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode((object) $content));

		curl_setopt($ch, CURLOPT_POST, true);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

		$result = curl_exec($ch);

		if(!$result)
			return curl_error( $ch );

		return $result;

	}
101465
public function exec()
    {
        // Set the header
        $this->buildHttpHeader();

        $parameters = [
            'headers' => $this->headers,
            'body' => $this->postFields,
            'curl' => $this->setPostCurlopts(),
        ];

        // Get all of the results 1000 at a time
        return  $this->sendData('POST', $parameters);
    }
1373693
protected function curlError($ch)
	{
		$errno = curl_errno($ch);
		$message = curl_error($ch);
		return array($errno, $message);
	}
875287
public function executeRequest()
    {

        // curl general
        $curl_options = [
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_SSL_VERIFYPEER => true,
            CURLOPT_CUSTOMREQUEST  => $this->requestType
        ];

        // set to post
        if ($this->requestType == 'POST') {
            $curl_options[CURLOPT_POST] = true;
        }

        // build url and append query params
        $url = $this->url($this->getUrl());
        $this->params[$this->oauth2->getAccessTokenName()] = $this->oauth2->getAccessToken();
        if (count($this->getParams()) > 0) {
            $url->setQuery($this->getParams());
        }
        $curl_options[CURLOPT_URL] = $url->val();

        // check request headers
        if (count($this->getHeaders()) > 0) {
            $header = [];
            foreach ($this->getHeaders() as $key => $parsed_urlvalue) {
                $header[] = "$key: $parsed_urlvalue";
            }
            $curl_options[CURLOPT_HTTPHEADER] = $header;
        }

        // init curl
        $ch = curl_init();
        curl_setopt_array($ch, $curl_options);

        // https handling
        if ($this->certificateFile != '') {
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
            curl_setopt($ch, CURLOPT_CAINFO, $this->certificateFile);
        } else {
            // bypass ssl verification
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        }

        // execute the curl request
        $result = curl_exec($ch);
        $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        $content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
        if ($curl_error = curl_error($ch)) {
            throw new OAuth2Exception($curl_error);
        } else {
            $json_decode = $this->jsonDecode($result, true);
        }
        curl_close($ch);

        return [
            'result'       => (null === $json_decode) ? $result : $json_decode,
            'code'         => $http_code,
            'content_type' => $content_type
        ];
    }
361876
private function get_headers_from_curl_response($headers)
    {
        $headers = explode("\r\n", $headers);
        array_shift($headers);
        foreach ($headers as $line) {
            if (strstr($line, ': ')) {
                list($key, $value) = explode(': ', $line);
                $result[$key] = $value;
            }
        }
        return $result;
    }
711279
protected function execute()
    {
        if ($this->url === null) {
            throw new CurlException('You have to provide an URL for the CurlRequest');
        }

        $ch = curl_init($this->url);
        curl_setopt_array($ch, $this->options);

        $this->content = curl_exec($ch);
        $this->infos   = curl_getinfo($ch);
        $this->error   = curl_error($ch);

        curl_close($ch);

        return $this->content;
    }
831542
public function send()
    {
        if (!$this->hasBeenInitialized())
            $this->_curlPrep();

        $result = curl_exec($this->_ch);

        $response = $this->buildResponse($result);

        curl_close($this->_ch);
        unset($this->_ch);

        return $response;
    }
713974
protected function curl() {
		$ch = curl_init($this->url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

		$response = json_decode(curl_exec($ch));

		curl_close($ch);

		return $response;
	}
803609
protected function executePutMultipart ($ch)
	{
        $post = $this->request_body;

		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
		curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
		curl_setopt($ch, CURLOPT_URL, $this->url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

		$this->response_body = curl_exec($ch);
		$this->response_info = curl_getinfo($ch);

        $this->closeCurlHandle();

	}
1339760
private function executePut($ch)
    {
        if (!is_string($this->requestBody)) {
            $this->buildPostBody();
        }

        $this->requestLength = strlen($this->requestBody);
        $fh = fopen('php://memory', 'rw');
        fwrite($fh, $this->requestBody);
        rewind($fh);

        curl_setopt($ch, CURLOPT_INFILE, $fh);
        curl_setopt($ch, CURLOPT_INFILESIZE, $this->requestLength);
        curl_setopt($ch, CURLOPT_PUT, true);

        $this->doExecute($ch);

        fclose($fh);
    }
244938
protected function execute_curl($options) {
		$ch = curl_init();
		curl_setopt_array($ch, $options);
		$returned = curl_exec($ch);
		$response = HttpClientResponse::instance_from_curl($ch, $returned);
		curl_close($ch);
		return $response;
	}
199724
static public function httpGet($url)
    {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($curl, CURLOPT_SSLVERSION, 1);
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_TIMEOUT, 30);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        list($content, $status) = array(curl_exec($curl), curl_getinfo($curl), curl_close($curl));
        return (intval($status["http_code"]) === 200) ? $content : false;
    }