public static function get_remote_filesize($url, $maxredirs = 2) {
		$parts = parse_url($url);
		if (empty($parts['host'])) {
			return false;
		}

		if ($parts['scheme'] === 'https') {
			$host = 'ssl://'.$parts['host'];
			$port = (isset($parts['port'])) ? $parts['port'] : 443;
		} else {
			$host = $parts['host'];
			$port = (isset($parts['port'])) ? $parts['port'] : 80;
		}
		$errno = $errstr = '';
		$timeout = 30;

		try {
			$fp = @fsockopen($host, $port, $errno, $errstr, $timeout);
		} catch (\Exception $e) {
			return false;
		}
		if (empty($fp)) {
			return false;
		}

		$path = $parts['path'];
		if (!empty($parts['query'])) {
			$path .= '?'.$parts['query'];
		}

		$out = 'HEAD '.$path.' HTTP/1.1'."\r\n"
			.'Host: '.$parts['host']."\r\n"
			.'Connection: Close'."\r\n\r\n";

		fwrite($fp, $out);
		$headers = '';
		while (!@feof($fp)) {
			$headers .= @fgets($fp, 128);
		}
		fclose($fp);

		$return = false;
		$headers = explode("\n", $headers);
		foreach ($headers as $header) {
			$hparts = explode(':', mb_strtolower($header), 2);
			if (!isset($hparts[1])) {
				continue;
			}
			list($hkey, $hval) = $hparts;
			switch ($hkey) {
				case 'location':
					if ($maxredirs > 0) {
						return static::get_remote_filesize(trim($hval), ($maxredirs - 1));
					} else {
						return false;
					}

				case 'content-length':
					return (int)trim($hval);
			}
		}
	}