Fetches a remote file

@param string $url The URL to download from

@return mixed The file contents or FALSE
@throws \Exception
439879
protected function _fetchRemoteFile($url)
  {
    // try to fetch the file
    if ($this->_use_curl) {
      $connection = $this->_getCurlInitialization($url);
      $this->_curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1);
      $this->_curl_setopt($connection, CURLOPT_HEADER, 0);
      // no SSL validation for downloading media
      $this->_curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, 1);
      $this->_curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, 2);
      $this->_curl_setopt($connection, CURLOPT_TIMEOUT_MS, $this->_timeouts['remote']);
      $this->_curl_setopt($connection, CURLOPT_CONNECTTIMEOUT_MS, $this->_timeouts['remote'] / 2);
      // find files that have been redirected
      $this->_curl_setopt($connection, CURLOPT_FOLLOWLOCATION, true);
      // process compressed images
      $this->_curl_setopt($connection, CURLOPT_ENCODING, 'gzip,deflate,sdch');
      $result = $this->_curl_exec($connection);
      if ($result !== false
        && $this->_curl_getinfo($connection, CURLINFO_HTTP_CODE) === 200
      ) {
        return $result;
      }
      throw new CodebirdMediaException('Downloading a remote media file failed.');
      return false;
    }
    // no cURL
    $contextOptions = [
      'http' => [
        'method'           => 'GET',
        'protocol_version' => '1.1',
        'timeout'          => $this->_timeouts['remote']
      ],
      'ssl' => [
        'verify_peer'  => false
      ]
    ];
    list($result, $headers) = $this->_getNoCurlInitialization($url, $contextOptions);
    if ($result !== false
      && preg_match('/^HTTP\/\d\.\d 200 OK$/', $headers[0])
    ) {
      return $result;
    }
    throw new CodebirdMediaException('Downloading a remote media file failed.');
    return false;
  }
673277
public static function getFileSizeHttp($url)
    {
        try {
            $res = get_headers($url, true);
            return isset($res['Content-Length']) ? $res['Content-Length'] : 0;
        } catch (\Exception $e) {
            return 0;
        }
    }
976110
public function loadUrl($url)
    {
        // Fetch HTTP content using Guzzle
        $response = $this->client->get($url);

        return $this->loadHtml($response->getBody()->__toString(), $url);
    }
674543
public function wget($httpFile, $remote)
    {
        if (! ini_get('allow_url_fopen')) {
            throw new \RuntimeException('allow_url_fopen must enabled');
        }
        if (! $fileData = file_get_contents($httpFile)) {
            throw new \RuntimeException('Can nat get file content');
        }
        $parseFile = $this->parseLastDirectory($remote);
        if (! file_put_contents($this->getWrapper("/$parseFile"), $fileData)) {
            throw new FileException('File not uploaded to ftp server');
        }
        return true;
    }
602709
public function download($url, $target, $override = false)
    {
        if (!$override && file_exists($target)) {
            return true;
        }

        $this->fs->mkdir(dirname($target), 0755);

        return $this->client
            ->get($url)
            ->setResponseBody($target)
            ->send()
            ->isSuccessful();
    }
503353
public function get($url)
    {
        $ch = curl_init();

        // set URL and other appropriate options
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

        // grab URL and pass it to the browser
        $content = curl_exec($ch);
        $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        // close cURL resource, and free up system resources
        if ($content === false) {
            throw new \Exception("CurlProxy error: " . curl_error($ch) . " when calling $url");
        }
        curl_close($ch);

        return $http_code == 200 && !empty($content) ? $content : false;
    }
248037
private function downloadFile($url)
    {
        $tmpFile = tempnam(sys_get_temp_dir(), 'utft');
        $extension = pathinfo($url, PATHINFO_EXTENSION);

        if (!empty($extension)) {
            $tmpFile = sprintf("%s.%s", $tmpFile, $extension);
        }

        $fp = fopen($tmpFile, 'w+');
        if (false === $fp) {
            throw new \RuntimeException(sprintf('Cannot open temporary file `%s`', $tmpFile));
        }

        $ch = curl_init();

        curl_setopt_array($ch, [
            CURLOPT_URL => $url,
            CURLOPT_BINARYTRANSFER => 1,
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_FILE => $fp,
            CURLOPT_TIMEOUT => 50,
        ]);

        if (false === curl_exec($ch)) {
            throw new \RuntimeException(sprintf('Cannot download remote file. Curl error: `%s`', curl_error($ch)));
        }
        curl_close($ch);

        return $tmpFile;
    }
715937
private function gateway($url)
	{
        if($this->method == 'POST') {
            $result = $this->createClient()->post($url);
        }
        else {
            $result = $this->createClient()->get($url);
        }

		if($result->getStatusCode() != 200) {
			throw new Exception(trans('location::errors.no_connect'));
		}

		$this->response = $result->getBody()->getContents();

		return $this->response;
	}
685192
public function fetchContent($url)
    {
        $this->logger->info('Graby is ready to fetch');

        $infos = $this->doFetchContent($url);

        // generate summary
        $infos['summary'] = $this->getExcerpt($infos['html']);

        return $infos;
    }
148058
public static function requestSimple($url)
    {
        if (function_exists('curl_init')) {
            $ch = curl_init();
            curl_setopt_array($ch, array(
                CURLOPT_URL => $url,
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_FOLLOWLOCATION => true,
                CURLOPT_USERAGENT => self::USER_AGENT
            ));
            $data = curl_exec($ch);
            if (curl_error($ch)) {
                trigger_error('Request cURL error:' . curl_error($ch), E_USER_ERROR);
            }
            $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
            if ($status != 200) {
                trigger_error("Request ({$url}) failed with status code {$status} (!= 200)", E_USER_ERROR);
            }
            curl_close($ch);
            return $data;
        } else {
            return file_get_contents($url, false, self::getContext());
        }
    }
952830
protected static function fetchUrl($url) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, ['User-Agent: Mozilla/5.0 (OSX) Gecko/20030208 Netscape/7.02']);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 1);
        
        $response = curl_exec($ch);
        
        $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
        $headers = substr($response, 0, $header_size);
        $body = substr($response, $header_size);
        
        // XXX check HTTP code
        // 404 -> not found
        // 200 -> ok
        // other -> fail
        
        return [
            'code' => $httpcode,
            'headers' => $headers,
            'body' => $body
        ];
    }
360351
public function getAction($url)
    {
        // Current route holder
        $current =  false;

        // Get requested method
        $method = $this->app->request->method() ? : 'GET';
        $method = strtolower($method);

        // Check all routes until one matches
        foreach ($this->routes[$method] as $route) {
            $matches = [];
            if (preg_match($route['pattern'], $url, $matches)) {
                if (!empty($matches)) {
                    array_shift($matches);
                    $route['params'] = array_combine(
                        $route['params'],
                        $matches
                    );
                }
                $current = $route;
                break;
            }
        }

        // Abort if none of the routes matched
        if (!$current) {
            throw new \Exception('Route not found', 404);
        }

        // Return current route
        return $current;
    }
952953
public function download($url)
	{
		$getResult = $this->session->get($url);

		if (!$getResult->success) {
			$this->error = array();
			$this->error['file'] = 'Download error (HTTP status: ' . $getResult->status_code . ')';
			$this->error['http'] = $getResult->status_code;
			return null;
		}
		return $getResult->body;
	}
1296147
static function downloadRemoteFile($url, $destinationFilename) {
		if (!ini_get('allow_url_fopen')) {
			throw new \Exception('allow_url_fopen is disable', 501);
		}

        $message = "File was not loaded";

		if (function_exists('curl_init')) {
		    try {
                $raw = file_get_contents($url);
            } catch (\Exception $e) {
                throw new \Exception($message, Consts::ERROR_CODE_BAD_REQUEST);
            }
		} else {
			$ch = curl_init($url);

			curl_setopt($ch, CURLOPT_HEADER, 0);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
			curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
			curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);// таймаут4

			$response = parse_url($url);
			curl_setopt($ch, CURLOPT_REFERER, $response['scheme'] . '://' . $response['host']);
			curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) ' .
                'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.99 YaBrowser/19.1.1.907 Yowser/2.5 Safari/537.36');


			$raw = curl_exec($ch);

            if (!$raw) {
                throw new \Exception($message, Consts::ERROR_CODE_BAD_REQUEST);
            }

            curl_close($ch);
        }

        if ($raw) {
            file_put_contents($destinationFilename, $raw);
        } else {
			throw new \Exception($message, Consts::ERROR_CODE_BAD_REQUEST);
		}
	}
799842
public function fget($remote)
    {
        if ($remote == '' || substr($remote, 0, 1) !== '/') {
            $remote = $this->dir . '/' . $remote;
        }
        $this->errorHandler->start();
        if (($handle = $this->driver->sftpFopen($this->resource, $remote, 'r+')) !== false) {
            rewind($handle);
            $this->errorHandler->stop();

            return $handle;
        }
        $this->errorHandler->stop();

        return false;
    }
318778
public function url_get_contents($url) {

        $content = '';

		if (\function_exists('curl_exec')){
            $conn = \curl_init($url);
            \curl_setopt($conn, CURLOPT_SSL_VERIFYPEER, true);
            \curl_setopt($conn, CURLOPT_FRESH_CONNECT,  true);
            \curl_setopt($conn, CURLOPT_RETURNTRANSFER, 1);
            \curl_setopt($conn,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17');
            \curl_setopt($conn, CURLOPT_AUTOREFERER, true);
            \curl_setopt($conn, CURLOPT_FOLLOWLOCATION, 1);
            \curl_setopt($conn, CURLOPT_VERBOSE, 0);
            $content = (\curl_exec($conn));
            \curl_close($conn);
        }
        if (!$content && \function_exists('file_get_contents')){
            $content = @\file_get_contents($url);
        }
        if (!$content && \function_exists('fopen') && function_exists('stream_get_contents')){
            $handle  = @\fopen ($url, "r");
            $content = @\stream_get_contents($handle);
        }
        return $content;
	}
140744
public function fetch($url)
    {
        if ($this->apiKey) {
            $url .= '&key='.$this->apiKey;
        }

        try {
            $json = json_decode(file_get_contents($url));
        } catch(\Exception $e) {
            throw new ServiceUnavailableException;
        }

        $this->checkApiError($json);

        return $json;
    }