linslin\yii2\curl\Curl::_httpRequest PHP Method

_httpRequest() private method

Performs HTTP request
private _httpRequest ( string $method, string $url, boolean $raw = false ) : mixed
$method string
$url string
$raw boolean if response body contains JSON and should be decoded -> helper.
return mixed
    private function _httpRequest($method, $url, $raw = false)
    {
        //set request type and writer function
        $this->setOption(CURLOPT_CUSTOMREQUEST, strtoupper($method));
        //check if method is head and set no body
        if ($method === 'HEAD') {
            $this->setOption(CURLOPT_NOBODY, true);
            $this->unsetOption(CURLOPT_WRITEFUNCTION);
        }
        //setup error reporting and profiling
        Yii::trace('Start sending cURL-Request: ' . $url . '\\n', __METHOD__);
        Yii::beginProfile($method . ' ' . $url . '#' . md5(serialize($this->getOption(CURLOPT_POSTFIELDS))), __METHOD__);
        /**
         * proceed curl
         */
        $this->_curl = curl_init($url);
        curl_setopt_array($this->_curl, $this->getOptions());
        $this->response = curl_exec($this->_curl);
        //check if curl was successful
        if ($this->response === false) {
            //set error code
            $this->errorCode = curl_errno($this->_curl);
            switch ($this->errorCode) {
                // 7, 28 = timeout
                case 7:
                case 28:
                    $this->responseCode = 'timeout';
                    return false;
                    break;
                default:
                    return false;
                    break;
            }
        }
        // Extract additional curl params
        $this->_extractAdditionalCurlParameter();
        //end yii debug profile
        Yii::endProfile($method . ' ' . $url . '#' . md5(serialize($this->getOption(CURLOPT_POSTFIELDS))), __METHOD__);
        //check responseCode and return data/status
        if ($this->getOption(CURLOPT_CUSTOMREQUEST) === 'HEAD') {
            return true;
        } else {
            $this->response = $raw ? $this->response : Json::decode($this->response);
            return $this->response;
        }
    }