HEAD request with PHP

March 30, 2017

Image for HEAD request with PHP from unsplash.com

If you want to perform a HEAD request with PHP on an URL you can use the stream functionality:

public function checkHTTPFile($url)

        'http' =>; [
            'method' => 'HEAD'

    $file_headers = @get_headers($url);

    if ($file_headers[0] == 'HTTP/1.1 200 OK') {
        return true;

    return false;



For more information on PHP's stream functions refer to the manual here: https://secure.php.net/manual/en/function.stream-context-set-default.php