public function head($url, $timeout = 10)
    {
        $p = parse_url($url);
        if (!isset($p['scheme'])) {
            $p = parse_url($this->absoluteURI($url));
        } elseif ($p['scheme'] != 'http') {
            throw new InvalidArgumentException(
                'Unsupported protocol: '. $p['scheme']
            );
        }

        $port = isset($p['port']) ? $p['port'] : 80;

        if (!$fp = @fsockopen($p['host'], $port, $eno, $estr, $timeout)) {
            throw new HTTP2_Exception("Connection error: $estr ($eno)");
        }

        $path  = !empty($p['path']) ? $p['path'] : '/';
        $path .= !empty($p['query']) ? '?' . $p['query'] : '';

        fputs($fp, "HEAD $path HTTP/1.0\r\n");
        fputs($fp, 'Host: ' . $p['host'] . ':' . $port . "\r\n");
        fputs($fp, "Connection: close\r\n\r\n");

        $response = rtrim(fgets($fp, 4096));
        if (preg_match("|^HTTP/[^\s]*\s(.*?)\s|", $response, $status)) {
            $headers['response_code'] = $status[1];
        }
        $headers['response'] = $response;

        while ($line = fgets($fp, 4096)) {
            if (!trim($line)) {
                break;
            }
            if (($pos = strpos($line, ':')) !== false) {
                $header = substr($line, 0, $pos);
                $value  = trim(substr($line, $pos + 1));

                $headers[$header] = $value;
            }
        }
        fclose($fp);
        return $headers;
    }
public function head($url, $timeout = 10)
    {
        $p = parse_url($url);
        if (!isset($p['scheme'])) {
            $p = parse_url($this->absoluteURI($url));
        } elseif ($p['scheme'] != 'http') {
            throw new InvalidArgumentException(
                'Unsupported protocol: '. $p['scheme']
            );
        }

        $port = isset($p['port']) ? $p['port'] : 80;

        if (!$fp = @fsockopen($p['host'], $port, $eno, $estr, $timeout)) {
            throw new HTTP2_Exception("Connection error: $estr ($eno)");
        }

        $path  = !empty($p['path']) ? $p['path'] : '/';
        $path .= !empty($p['query']) ? '?' . $p['query'] : '';

        fputs($fp, "HEAD $path HTTP/1.0\r\n");
        fputs($fp, 'Host: ' . $p['host'] . ':' . $port . "\r\n");
        fputs($fp, "Connection: close\r\n\r\n");

        $response = rtrim(fgets($fp, 4096));
        if (preg_match("|^HTTP/[^\s]*\s(.*?)\s|", $response, $status)) {
            $headers['response_code'] = $status[1];
        }
        $headers['response'] = $response;

        while ($line = fgets($fp, 4096)) {
            if (!trim($line)) {
                break;
            }
            if (($pos = strpos($line, ':')) !== false) {
                $header = substr($line, 0, $pos);
                $value  = trim(substr($line, $pos + 1));

                $headers[$header] = $value;
            }
        }
        fclose($fp);
        return $headers;
    }
public function head ( $ url , $ timeout = 10 ) { $ p = parse_url ( $ url ) ; if ( ! isset ( $ p [ 'scheme' ] ) ) { $ p = parse_url ( $ this -> absoluteURI ( $ url ) ) ; } elseif ( $ p [ 'scheme' ] != 'http' ) { throw new InvalidArgumentException ( 'Unsupported protocol: ' . $ p [ 'scheme' ] ) ; } $ port = isset ( $ p [ 'port' ] ) ? $ p [ 'port' ] : 80 ; if ( ! $ fp = @ fsockopen ( $ p [ 'host' ] , $ port , $ eno , $ estr , $ timeout ) ) { throw new HTTP2_Exception ( "Connection error: $estr ($eno)" ) ; } $ path = ! empty ( $ p [ 'path' ] ) ? $ p [ 'path' ] : '/' ; $ path .= ! empty ( $ p [ 'query' ] ) ? '?' . $ p [ 'query' ] : '' ; fputs ( $ fp , "HEAD $path HTTP/1.0\r\n" ) ; fputs ( $ fp , 'Host: ' . $ p [ 'host' ] . ':' . $ port . "\r\n" ) ; fputs ( $ fp , "Connection: close\r\n\r\n" ) ; $ response = rtrim ( fgets ( $ fp , 4096 ) ) ; if ( preg_match ( "|^HTTP/[^\s]*\s(.*?)\s|" , $ response , $ status ) ) { $ headers [ 'response_code' ] = $ status [ 1 ] ; } $ headers [ 'response' ] = $ response ; while ( $ line = fgets ( $ fp , 4096 ) ) { if ( ! trim ( $ line ) ) { break ; } if ( ( $ pos = strpos ( $ line , ':' ) ) !== false ) { $ header = substr ( $ line , 0 , $ pos ) ; $ value = trim ( substr ( $ line , $ pos + 1 ) ) ; $ headers [ $ header ] = $ value ; } } fclose ( $ fp ) ; return $ headers ; }
Sends a "HEAD" HTTP command to a server and returns the headers
as an associative array.

Example output could be:
<code>
Array
(
[response_code] => 200          // The HTTP response code
[response] => HTTP/1.1 200 OK   // The full HTTP response string
[Date] => Fri, 11 Jan 2002 01:41:44 GMT
[Server] => Apache/1.3.20 (Unix) PHP/4.1.1
[X-Powered-By] => PHP/4.1.1
[Connection] => close
[Content-Type] => text/html
)
</code>

@param string  $url     A valid URL, e.g.: http://pear.php.net/credits.php
@param integer $timeout Timeout in seconds (default = 10)

@return array Returns associative array of response headers on success

@throws HTTP2_Exception          When connecting fails
@throws InvalidArgumentException When the protocol is not uspported

@see HTTP_Client::head()
@see HTTP_Request
Sends a HEAD HTTP command to a server and returns the headers as an associative array .