private function execute($url, array $headers = array(), $callable = null)
    {
        $curl = curl_init();

        curl_setopt($curl, CURLOPT_URL, $this->fixUrl($url));
        curl_setopt($curl, CURLOPT_HEADER, true);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

        if ($this->getMaxRedirects() > 0) {
            curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
            curl_setopt($curl, CURLOPT_MAXREDIRS, $this->getMaxRedirects());
        }

        if (!empty($headers)) {
            curl_setopt($curl, CURLOPT_HTTPHEADER, $this->fixHeaders($headers));
        }

        if ($callable !== null) {
            call_user_func($callable, $curl);
        }

        if (($response = curl_exec($curl)) === false) {
            $error = curl_error($curl);
            curl_close($curl);

            throw HttpAdapterException::cannotFetchUrl($url, $this->getName(), $error);
        }

        $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
        $headersSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
        $effectiveUrl = curl_getinfo($curl, CURLINFO_EFFECTIVE_URL);

        curl_close($curl);

        $headers = substr($response, 0, $headersSize);
        $body = substr($response, $headersSize);

        return $this->createResponse($statusCode, $url, $headers, $body, $effectiveUrl);
    }
private function execute($url, array $headers = array(), $callable = null)
    {
        $curl = curl_init();

        curl_setopt($curl, CURLOPT_URL, $this->fixUrl($url));
        curl_setopt($curl, CURLOPT_HEADER, true);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

        if ($this->getMaxRedirects() > 0) {
            curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
            curl_setopt($curl, CURLOPT_MAXREDIRS, $this->getMaxRedirects());
        }

        if (!empty($headers)) {
            curl_setopt($curl, CURLOPT_HTTPHEADER, $this->fixHeaders($headers));
        }

        if ($callable !== null) {
            call_user_func($callable, $curl);
        }

        if (($response = curl_exec($curl)) === false) {
            $error = curl_error($curl);
            curl_close($curl);

            throw HttpAdapterException::cannotFetchUrl($url, $this->getName(), $error);
        }

        $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
        $headersSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
        $effectiveUrl = curl_getinfo($curl, CURLINFO_EFFECTIVE_URL);

        curl_close($curl);

        $headers = substr($response, 0, $headersSize);
        $body = substr($response, $headersSize);

        return $this->createResponse($statusCode, $url, $headers, $body, $effectiveUrl);
    }
private function execute ( $ url , array $ headers = array ( ) , $ callable = null ) { $ curl = curl_init ( ) ; curl_setopt ( $ curl , CURLOPT_URL , $ this -> fixUrl ( $ url ) ) ; curl_setopt ( $ curl , CURLOPT_HEADER , true ) ; curl_setopt ( $ curl , CURLOPT_RETURNTRANSFER , true ) ; if ( $ this -> getMaxRedirects ( ) > 0 ) { curl_setopt ( $ curl , CURLOPT_FOLLOWLOCATION , true ) ; curl_setopt ( $ curl , CURLOPT_MAXREDIRS , $ this -> getMaxRedirects ( ) ) ; } if ( ! empty ( $ headers ) ) { curl_setopt ( $ curl , CURLOPT_HTTPHEADER , $ this -> fixHeaders ( $ headers ) ) ; } if ( $ callable !== null ) { call_user_func ( $ callable , $ curl ) ; } if ( ( $ response = curl_exec ( $ curl ) ) === false ) { $ error = curl_error ( $ curl ) ; curl_close ( $ curl ) ; throw HttpAdapterException :: cannotFetchUrl ( $ url , $ this -> getName ( ) , $ error ) ; } $ statusCode = curl_getinfo ( $ curl , CURLINFO_HTTP_CODE ) ; $ headersSize = curl_getinfo ( $ curl , CURLINFO_HEADER_SIZE ) ; $ effectiveUrl = curl_getinfo ( $ curl , CURLINFO_EFFECTIVE_URL ) ; curl_close ( $ curl ) ; $ headers = substr ( $ response , 0 , $ headersSize ) ; $ body = substr ( $ response , $ headersSize ) ; return $ this -> createResponse ( $ statusCode , $ url , $ headers , $ body , $ effectiveUrl ) ; }
Fetches a response from an URL.

@param string   $url      The url to fetch.
@param array    $headers  The http headers.
@param callable $callable A callable function executed before fetching the url.

@return \Widop\HttpAdapter\HttpResponse The response.
Fetches a response from an URL .