/** * Options supported: * - follow.redirects - Follow HTTP redirects code * - follow.trace - Save full redirects history * - follow.maxcount - Max number of redirects * - headers.lowercase - Convert HTTP headers into lower-case strings */ protected static function _doGetHead($url, $method, $options = array()) { HttpUtils::update_max_execution_time(); $method = strtoupper($method); $arr = parse_url($url); $arr['port'] = isset($arr['port']) ? $arr['port'] : 80; $errno = $errstr = null; $R = new StdClass(); $R->isError = false; if ($method != 'GET' && $method != 'HEAD') { $R->isError = "Invalid method {$method}. Only GET & HEAD allowed"; return $R; } $f = @fsockopen($arr['host'], $arr['port'], $errno, $errstr, 600); if (!$f) { $R->isError = " Connecting to {$arr['host']}:{$arr['port']} failed: {$errstr}, {$errno}"; return $R; } stream_set_blocking($f, 0); $req = "{$method} {$arr['path']}" . (empty($arr['query']) ? '' : '?' . $arr['query']) . " HTTP/1.0\r\n"; $req .= "Host: {$arr['host']}\r\n"; $req .= "Connection: Close\r\n"; if (!empty($arr['user'])) { $req .= "Authorization: Basic " . base64_encode("{$arr['user']}:{$arr['pass']}") . "\r\n"; } $req .= "\r\n"; fputs($f, $req); $res = ''; while (!feof($f)) { $res .= fgets($f, 1024); } fclose($f); // Parse result return HttpUtils::parseHttpResponse($res, $options); }