HTTP request via low-level TCP/IP socket
@return array
@param $url string
@param $options array
488567
protected function _socket($url,$options) {
		$eol="\r\n";
		$headers=[];
		$body='';
		$parts=parse_url($url);
		$hostname=$parts['host'];
		$proxy=false;
		if ($parts['scheme']=='https')
			$parts['host']='ssl://'.$parts['host'];
		if (empty($parts['port']))
			$parts['port']=$parts['scheme']=='https'?443:80;
		if (empty($parts['path']))
			$parts['path']='/';
		if (empty($parts['query']))
			$parts['query']='';
		if (isset($options['proxy'])) {
			$req=$url;
			$pp=parse_url($options['proxy']);
			$proxy=$pp['scheme'];
			if ($pp['scheme']=='https')
				$pp['host']='ssl://'.$pp['host'];
			if (empty($pp['port']))
				$pp['port']=$pp['scheme']=='https'?443:80;
			$socket=@fsockopen($pp['host'],$pp['port'],$code,$err);
		} else {
			$req=$parts['path'].($parts['query']?('?'.$parts['query']):'');
			$socket=@fsockopen($parts['host'],$parts['port'],$code,$err);
		}
		if ($socket) {
			stream_set_blocking($socket,TRUE);
			stream_set_timeout($socket,isset($options['timeout'])?
				$options['timeout']:ini_get('default_socket_timeout'));
			if ($proxy=='socks4') {
				// SOCKS4; http://en.wikipedia.org/wiki/SOCKS#Protocol
				$packet="\x04\x01".pack("n", $parts['port']).
					pack("H*",dechex(ip2long(gethostbyname($hostname))))."\0";
				fputs($socket, $packet, strlen($packet));
				$response=fread($socket, 9);
				if (strlen($response)==8 && (ord($response[0])==0 || ord($response[0])==4)
					&& ord($response[1])==90) {
					$options['header'][]='Host: '.$hostname;
				} else
					$err='Socket Status '.ord($response[1]);
			}
			fputs($socket,$options['method'].' '.$req.' HTTP/1.0'.$eol);
			fputs($socket,implode($eol,$options['header']).$eol.$eol);
			if (isset($options['content']))
				fputs($socket,$options['content'].$eol);
			// Get response
			$content='';
			while (!feof($socket) &&
				($info=stream_get_meta_data($socket)) &&
				!$info['timed_out'] && !connection_aborted() &&
				$str=fgets($socket,4096))
				$content.=$str;
			fclose($socket);
			$html=explode($eol.$eol,$content,2);
			$body=isset($html[1])?$html[1]:'';
			$headers=array_merge($headers,$current=explode($eol,$html[0]));
			$match=NULL;
			foreach ($current as $header)
				if (preg_match('/Content-Encoding: (.+)/i',$header,$match))
					break;
			if ($match)
				switch ($match[1]) {
					case 'gzip':
						$body=gzdecode($body);
						break;
					case 'deflate':
						$body=gzuncompress($body);
						break;
				}
			if ($options['follow_location'] &&
				preg_grep('/HTTP\/1\.\d 3\d{2}/',$headers) &&
				preg_match('/Location: (.+?)'.preg_quote($eol).'/',
				$html[0],$loc)) {
				$options['max_redirects']--;
				return $this->request($loc[1],$options);
			}
		}
		return [
			'body'=>$body,
			'headers'=>$headers,
			'engine'=>'socket',
			'cached'=>FALSE,
			'error'=>$err
		];
	}
131732
protected static function parse($url, array $options = [])
    {
        if (!empty($options['lastmod']) && !is_string($options['lastmod'])) {
            $options['lastmod'] = $options['lastmod']->format('c');
        }
        $options += ['priority' => '0.5'];

        return array_merge(['loc' => Router::url($url, true)], $options);
    }
319092
private function getUriHostAndPath($url)
    {
        try {
            $uri = HttpUri::createFromString($url);
        } catch (InvalidArgumentException $e) {
            return ['', ''];
        }

        $host = $uri->getHost();
        $port = $uri->getPort();
        if (!$port && $uri->getScheme() == 'https') {
            $port = 443;
        }
        if ($port) {
            $host .= ':'.strval($port);
        }
        $path = $uri->getPath();
        if (!$path) {
            $path = '/';
        }

        return [$host, $path];
    }
578086
public function get($url, array $options = [])
	{
        if(!is_array($options)) {
            $options = [];
        }
        return $this->embed->get($url, $options);
    }
876219
public function get($url, $options = [], $body = null, $raw = true)
    {
        return $this->httpRequest('GET', $this->createUrl($url, $options), $body, $raw);
    }
904340
public function addURL($url,$options=array()) {
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        foreach($options as $option=>$value) {
            curl_setopt($ch, $option, $value);
        }
        return $this->addCurl($ch);
    }
893833
private function getOptions($options)
    {
        $conf = [
            CURLOPT_HEADER => false,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_FOLLOWLOCATION => true
        ];

        if (isset($options['timeout'])) {
            $conf[CURLOPT_TIMEOUT_MS] = $options['timeout'] * 1000;
        }
        if (isset($options['connect_timeout'])) {
            $conf[CURLOPT_CONNECTTIMEOUT_MS] = $options['connect_timeout'] * 1000;
        }

        return $conf;
    }
1112151
public function head($url, $options = array()) {
        $curlOptions['CURLOPT_HTTPGET'] = 0;
        $curlOptions['CURLOPT_HEADER']  = 1;
        $curlOptions['CURLOPT_NOBODY']  = 1;
        return $this->request($url, $curlOptions);
    }
788497
protected function request($url, $options = array(), $acceptheader = 'application/json') {
        $murl = new moodle_url($url);

        if ($this->accesstoken) {
            if ($this->use_http_get()) {
                // If using HTTP GET add as a parameter.
                $murl->param('access_token', $this->accesstoken->token);
            } else {
                $this->setHeader('Authorization: Bearer '.$this->accesstoken->token);
            }
        }

        if ($acceptheader) {
            $this->setHeader('Accept: ' . $acceptheader);
        }

        $response = parent::request($murl->out(false), $options);

        $this->resetHeader();

        return $response;
    }
1276091
protected static function createViaStreamWrapper($url, array $options = [])
    {
        $clientOptions = isset($options['client']) ? (array)$options['client'] : [];
        $opts = array_merge_recursive([
            'http' => [
                'method' => 'GET',
                'protocol_version' => 1.1,
                'user_agent' => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.466.4 Safari/534.3',
                'max_redirects' => 10,
                'timeout' => 10.0,
                'header' => "Accept-language: en\r\n",
            ]
        ], $clientOptions);
        $context = stream_context_create($opts);
        $requestOptions = isset($options['request']) ? (array)$options['request'] : [];
        stream_context_set_params($context, $requestOptions);
        $response = @file_get_contents($url, false, $context);
        return self::createFromString($response);
    }
814303
private function simpleGet($url, array $options = [])
    {
        return (array) \GuzzleHttp\json_decode(
          $this->getConnector()
               ->getClient()
               ->request('get', $url, $options)
               ->getBody()
               ->getContents(),
          true
        );
    }
600402
protected function request($url, $curlOptions = array()) {
        // create curl instance
        $curl = curl_init($url);
        $curlOptions['url'] = $url;
        $this->resetCurlOptions();
        $this->prepareRequest($curl, $curlOptions);
        if ($this->cacheInstance && $httpbody = $this->cacheInstance->get($this->curlOptions)) {
            return $httpbody;
        } else {
            $httpbody = curl_exec($curl);
            if ($this->cacheInstance) {
                $this->cacheInstance->set($this->curlOptions, $httpbody);
            }
        }

        $this->info  = curl_getinfo($curl);
        $this->error = curl_error($curl);

        if ($this->debug){
            var_dump($this->info);
            var_dump($this->error);
        }

        curl_close($curl);

        $response = new CurlHttpResponse($this->info['http_code'], $this->responseHeaders, $httpbody);

        if (!empty($this->error)) {
            throw new \Exception($this->error);
        }
        return $response;
    }
734299
public function httpPost($url, array $postOptions, array $options = [])
    {
        Yii::info([
            'url' => $url,
            'postOptions' => $postOptions,
            'options' => $options
        ], __METHOD__);
        return $this->parseHttpRequest(function($url, $postOptions) {
            return $this->http($url, [
                CURLOPT_POST => true,
                CURLOPT_POSTFIELDS => $postOptions
            ]);
        }, $this->httpBuildQuery($url, $options), $postOptions);
    }
239347
public function request($url, $options)
    {
        $this->url = $url;
        $this->options = array_replace_recursive($this->settings['defaults'], $options);

        try {
            return $this->handleRequest();
        } catch (TokenExpiredException $e) {
            $this->refresh();

            return $this->handleRequest();
        }
    }
450305
public function get($url, $params = array(), $options = array()) {
        $options['CURLOPT_HTTPGET'] = 1;

        if (!empty($params)) {
            $url .= (stripos($url, '?') !== false) ? '&' : '?';
            $url .= http_build_query($params, '', '&');
        }
        return $this->request($url, $options);
    }
510318
public function makeRequest($url, $options = [], $parseResponse = true)
    {
        return $this->request($url, $options, $parseResponse, function ($url, $method, $headers, $data) {
            return $this->getHttpClient()->retrieveResponse($url, $data, $headers, $method);
        });
    }
248729
public function get($url, $params = [], $options = [], $headers = []) {
        return $this->makeCall('get', $url, $params, $options, $headers);
    }