How can one check if a URL exists in PHP without downloading the entire file?

To check if a URL exists in PHP without downloading the entire file, you can use the `get_headers()` function to send a HEAD request to the URL and retrieve the headers. By checking the response code in the headers, you can determine if the URL exists without downloading the entire file.

function urlExists($url){
    $headers = @get_headers($url);
    if($headers && strpos($headers[0], '200')){
        return true;
    } else {
        return false;
    }
}

$url = "https://www.example.com";
if(urlExists($url)){
    echo "URL exists";
} else {
    echo "URL does not exist";
}