Return a globally cached cURL handle, configured for current instance

@return resource
512509
protected function getHandle()
	{
		if (!isset(self::$handle))
		{
			self::$handle = $this->getNewHandle();
		}

		curl_setopt(self::$handle, CURLOPT_SSL_VERIFYPEER, $this->sslVerifyPeer);
		curl_setopt(self::$handle, CURLOPT_TIMEOUT,        $this->timeout);

		return self::$handle;
	}
866065
protected function _getOriginalRequest()
    {
        $request = $this->escort->request;
        $handler = $request->getParam('error_handler');

        if ($handler) {
            return $handler->request;
        }

        return $request;
    }
215080
protected function buildRequest()
    {
        if (self::STATE_NEW === $this->state)
        {
            throw new \RuntimeException(sprintf(
                '%s::execute - Could not execute request, curl has not been initialized.',
                get_class($this)
            ));
        }

        if (self::STATE_EXECUTED === $this->state)
            $this->close();

        if (self::STATE_CLOSED === $this->state)
            $this->initialize($this->currentRequestUrl, false);

        // Create curl handle resource
        $this->ch = curl_init($this->currentRequestUrl);
        if (false === $this->ch)
        {
            throw new \RuntimeException(sprintf(
                'Unable to initialize curl with url: %s',
                $this->getRequestUrl()
            ));
        }

        // Set the Header array (if any)
        if (count($this->requestHeaders) > 0)
        {
            $headers = array();
            foreach($this->requestHeaders as $k=>$v)
            {
                $headers[] = vsprintf('%s: %s', array($k, $v));
            }
            $this->setCurlOpt(CURLOPT_HTTPHEADER, $headers);
        }

        // Return the Request Header as part of the curl_info array unless they specify otherwise
        if (!$this->curlOptSet(CURLINFO_HEADER_OUT))
            $this->setCurlOpt(CURLINFO_HEADER_OUT, true);

        // If the user has opted to return the data, rather than save to file or output directly,
        // attempt to get headers back in the response for later use if they have not specified
        // otherwise.
        if ($this->getCurlOptValue(CURLOPT_RETURNTRANSFER) && !$this->curlOptSet(CURLOPT_HEADER))
            $this->setCurlOpt(CURLOPT_HEADER, true);

        // Set the CURLOPTS
        if (false === curl_setopt_array($this->ch, $this->curlOpts))
        {
            throw new \RuntimeException(sprintf(
                'Unable to specify curl options, please ensure you\'re passing in valid constants.  Specified opts: %s',
                json_encode($this->getCurlOpts())
            ));
        }
    }
5403
public static function get()
    {
        // Use DynamoDB for distributed session storage if it's configured
        $awsDynamoDBSessionTable = Environment::getEnv('AWS_DYNAMODB_SESSION_TABLE');
        if (!empty($awsDynamoDBSessionTable)) {
            $awsRegionName = Environment::getEnv('AWS_REGION_NAME');
            $awsDynamoDBEndpoint = Environment::getEnv('AWS_DYNAMODB_ENDPOINT');
            $awsAccessKey = Environment::getEnv('AWS_ACCESS_KEY');
            $awsSecretKey = Environment::getEnv('AWS_SECRET_KEY');

            $dynamoOptions = array('region' => $awsRegionName);

            // This endpoint can be set for locally testing DynamoDB.
            // see http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html
            if (!empty($awsDynamoDBEndpoint)) {
                $dynamoOptions['endpoint'] = $awsDynamoDBEndpoint;
            }

            if (!empty($awsAccessKey) && !empty($awsSecretKey)) {
                $dynamoOptions['credentials']['key'] = $awsAccessKey;
                $dynamoOptions['credentials']['secret'] = $awsSecretKey;
            } else {
                // cache credentials when IAM fetches the credentials from EC2 metadata service
                // this will use doctrine/cache (included via composer) to do the actual caching into APCu
                // http://docs.aws.amazon.com/aws-sdk-php/guide/latest/performance.html#cache-instance-profile-credentials
                $dynamoOptions['credentials'] = new DoctrineCacheAdapter(new ApcuCache());
            }

            return new static($dynamoOptions, $awsDynamoDBSessionTable);
        }

        return null;
    }
1323190
private function curlInit()
    {
        $curlHandle = curl_init();

        curl_setopt($curlHandle, CURLOPT_ENCODING, 'gzip,deflate');

        curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curlHandle, CURLOPT_VERBOSE, false);
        curl_setopt($curlHandle, CURLOPT_HEADER, true);

        curl_setopt($curlHandle, CURLOPT_USERPWD, (string)$this->credentials);

        curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER, false);
		curl_setopt($curlHandle, CURLOPT_SSL_VERIFYHOST, 2);

		curl_setopt($curlHandle, CURLOPT_TIMEOUT, 4);

        curl_setopt($curlHandle, CURLOPT_FOLLOWLOCATION, true);

        return $curlHandle;
    }
4189
public function detectHttpClientHandler()
    {
        $handler = null;
        if (class_exists('GuzzleHttp\Client')) {
            $handler = new GuzzleHttpClient();
        } elseif (function_exists('curl_init')) {
            $handler = new CurlHttpClient();
        } else {
            $handler = new StreamHttpClient();
        }
        return $handler;
    }
782437
public function getCurrentWindowHandle()
    {
        $command = $this->driver->factoryCommand('window_handle', WebDriver_Command::METHOD_GET);
        $result = $this->driver->curl($command);
        return $result['value'];
    }
1113970
protected function getGuzzleHandler()
    {
        if (property_exists($this, 'app') && isset($this->app['guzzle_handler']) && is_string($this->app['guzzle_handler'])) {
            $handler = $this->app['guzzle_handler'];

            return new $handler();
        }

        return \GuzzleHttp\choose_handler();
    }
253031
public function getRequestHandler()
    {
        if (isset($this->requestHandler))
            return $this->requestHandler;

        // now instantiating handler from config
        $handlerClass = "\\" . ltrim($this->handlerClass, "\\");
        if (!class_exists($handlerClass))
            throw new RuntimeException("Unable to create HTTP Handler instance with class: " . var_export($handlerClass, true));

        $this->requestHandler = new $handlerClass();
        return $this->requestHandler;
    }
713940
public function getMainHandle()
    {
        if (!$this->mh) {
            $this->mh = curl_multi_init();

            $this->errors = [];
        }

        return $this->mh;
    }
363873
private function createCurlHandler()
    {
        $handlerOptions = [
            'handle_factory' => new CurlFactory(3),
        ];

        if (\function_exists('curl_multi_exec') && \function_exists('curl_exec')) {
            return Proxy::wrapSync(new CurlMultiHandler($handlerOptions), new CurlHandler($handlerOptions));
        }

        if (\function_exists('curl_exec')) {
            return new CurlHandler($handlerOptions);
        }

        if (\function_exists('curl_multi_exec')) {
            return new CurlMultiHandler($handlerOptions);
        }

        throw new \RuntimeException('Blackfire Player requires cURL.');
    }
659710
public function get()
    {
        $url = $this->getUrl('get');
        $json = $this->curl->get($url);

        return $json;
    }
471612
private function getHandle()
    {
        if ($this->_useKeepAlive && $this->_handle && is_resource($this->_handle)) {
            // keep-alive and handle was created already
            $handle = $this->_handle;

            // check if connection is still valid
            if (!feof($handle)) {
                // connection still valid
                return $handle;
            }

            // close handle
            $this->closeHandle();

            if (!$this->_options[ConnectionOptions::OPTION_RECONNECT]) {
                // if reconnect option not set, this is the end
                throw new ClientException('Server has closed the connection already.');
            }
        }

        // no keep-alive or no handle available yet or a reconnect
        $handle = HttpHelper::createConnection($this->_options);

        if ($this->_useKeepAlive && is_resource($handle)) {
            $this->_handle = $handle;
        }

        return $handle;
    }
1305854
private function cachedAllGlobal() {
		if (!isset($this->{__METHOD__})) {
			$this->{__METHOD__} = array_merge($this->cachedGlobalI(), $this->cachedGlobalObjectsI());
		}
		return $this->{__METHOD__};
	}
973569
public function connect() 
	{
		if($this->getResource()) {
			$this->close();
		}

		$resource = curl_init();

		curl_setopt($resource,CURLOPT_CONNECTTIMEOUT,$this->getTimeout());
	
		$this->setResource($resource);
		parent::connect();
		return $this;
	}
1019463
protected function getRestResource()
    {
        $parentResource = $this->getParentResource();

        if ($parentResource !== null) {
            $childResource = $parentResource->getChildResource($this->matchingUrl);
            if ($childResource) {
                $childResource->setUrlHandler($this);
                return $childResource;
            }
        }

        $className = $this->apiResourceClassName;
        /** @var RestResource $resource */
        $resource = new $className($this->getParentResource());
        $resource->setUrlHandler($this);

        return $resource;
    }
960983
public function get_curl_object() {
        if (!is_null($this->curl)) {
            return $this->curl;
        }

        // Connection to Solr is allowed to use 'localhost' and other potentially blocked hosts/ports.
        $this->curl = new \curl(['ignoresecurity' => true]);

        $options = array();
        // Build the SSL options. Based on pecl-solr and general testing.
        if (!empty($this->config->secure)) {
            if (!empty($this->config->ssl_cert)) {
                $options['CURLOPT_SSLCERT'] = $this->config->ssl_cert;
                $options['CURLOPT_SSLCERTTYPE'] = 'PEM';
            }

            if (!empty($this->config->ssl_key)) {
                $options['CURLOPT_SSLKEY'] = $this->config->ssl_key;
                $options['CURLOPT_SSLKEYTYPE'] = 'PEM';
            }

            if (!empty($this->config->ssl_keypassword)) {
                $options['CURLOPT_KEYPASSWD'] = $this->config->ssl_keypassword;
            }

            if (!empty($this->config->ssl_cainfo)) {
                $options['CURLOPT_CAINFO'] = $this->config->ssl_cainfo;
            }

            if (!empty($this->config->ssl_capath)) {
                $options['CURLOPT_CAPATH'] = $this->config->ssl_capath;
            }
        }

        // Set timeout as for Solr client.
        $options['CURLOPT_TIMEOUT'] = !empty($this->config->server_timeout) ? $this->config->server_timeout : '30';

        $this->curl->setopt($options);

        if (!empty($this->config->server_username) && !empty($this->config->server_password)) {
            $authorization = $this->config->server_username . ':' . $this->config->server_password;
            $this->curl->setHeader('Authorization: Basic ' . base64_encode($authorization));
        }

        return $this->curl;
    }