src/Support/Web/WebRequest.php
/**
     * Executes this request with the specified request method and the given options.
     *
     * @param string $method
     * @param array $options
     *
     * @return WebResponse
     * @throws WebRequestException Thrown for network, connection, or configuration errors.
     */
Executes this request with the specified request method and the given options.
@param string $method
@param array $options

@return WebResponse
@throws WebRequestException Thrown for network, connection, or configuration errors.
Executes this request with the specified request method and the given options . @param string $method @param array $options @return WebResponse @throws WebRequestException Thrown for network connection or configuration errors .
public function execute($method = 'get', $options = [], $headers = []) {
        $startTime = microtime(true);
        $headers = $this->calculateHeaders($headers);
        $responseHeaders = [];
        $httpVersion = null;
        $httpMessage = null;
        $options = $this->calculateOptions($options, $method, $this->createHeaderParser($responseHeaders, $httpVersion, $httpMessage));
        $isFollowing = $this->isFollowingRedirects();
        $uri = $lastLocation = $this->uri;
        $redirections = 0;
        $traces = [];
        while (true) {
            $handle = $this->createHandle($uri, $options, $headers);
            $body = @curl_exec($handle);
            $traces[] = new WebResponseTrace($uri, $handle);
            if (curl_errno($handle) > 0) {
                throw new WebRequestException($this, curl_error($handle), curl_errno($handle));
            }
            if ($isFollowing) {
                $location = isset($responseHeaders['location']) ? $responseHeaders['location'] : null;
                if (!is_null($location)) {
                    if (($redirections++) >= $this->getOption(CURLOPT_MAXREDIRS)) {
                        throw new WebRequestException($this, 'Too many redirects', CURLE_TOO_MANY_REDIRECTS);
                    }
                    $previousUri = $uri;
                    $uri = $this->parseRedirectUri($lastLocation, $location);
                    $responseHeaders = [];
                    $httpVersion = null;
                    $lastLocation = $previousUri;
                    continue;
                }
            }
            $totalTime = (microtime(true) - $startTime);
            if (isset($options[CURLOPT_WRITEFUNCTION])) {
                return;
            }
            return new WebResponse($this, $handle, $responseHeaders, $body, $totalTime, $traces, $httpVersion, $httpMessage);
        }
    }
public function execute ( $ method = 'get' , $ options = [ ] , $ headers = [ ] ) { $ startTime = microtime ( true ) ; $ headers = $ this -> calculateHeaders ( $ headers ) ; $ responseHeaders = [ ] ; $ httpVersion = null ; $ httpMessage = null ; $ options = $ this -> calculateOptions ( $ options , $ method , $ this -> createHeaderParser ( $ responseHeaders , $ httpVersion , $ httpMessage ) ) ; $ isFollowing = $ this -> isFollowingRedirects ( ) ; $ uri = $ lastLocation = $ this -> uri ; $ redirections = 0 ; $ traces = [ ] ; while ( true ) { $ handle = $ this -> createHandle ( $ uri , $ options , $ headers ) ; $ body = @ curl_exec ( $ handle ) ; $ traces [ ] = new WebResponseTrace ( $ uri , $ handle ) ; if ( curl_errno ( $ handle ) > 0 ) { throw new WebRequestException ( $ this , curl_error ( $ handle ) , curl_errno ( $ handle ) ) ; } if ( $ isFollowing ) { $ location = isset ( $ responseHeaders [ 'location' ] ) ? $ responseHeaders [ 'location' ] : null ; if ( ! is_null ( $ location ) ) { if ( ( $ redirections ++ ) >= $ this -> getOption ( CURLOPT_MAXREDIRS ) ) { throw new WebRequestException ( $ this , 'Too many redirects' , CURLE_TOO_MANY_REDIRECTS ) ; } $ previousUri = $ uri ; $ uri = $ this -> parseRedirectUri ( $ lastLocation , $ location ) ; $ responseHeaders = [ ] ; $ httpVersion = null ; $ lastLocation = $ previousUri ; continue ; } } $ totalTime = ( microtime ( true ) - $ startTime ) ; if ( isset ( $ options [ CURLOPT_WRITEFUNCTION ] ) ) { return ; } return new WebResponse ( $ this , $ handle , $ responseHeaders , $ body , $ totalTime , $ traces , $ httpVersion , $ httpMessage ) ; } }
Executes this request with the specified request method and the given options.
Executes this request with the specified request method and the given options .
// Time profiling // Get request headers // Get options and set the header parser // Determine if we should follow redirects // Perform requests in a loop until we're done // Handle client errors // Follow redirections if configured to do so // If $redirect is not null, then the page wants to redirect // Make sure we're under the redirect limit // Parse and update the uri // Clean up for next iteration // Continue to the next iteration // Calculate total time // Return the response instance