HEAD request with PHP

Image for HEAD request with PHP from unsplash.com

By Andrew McCombe
March 30, 2017

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