What are the potential pitfalls of using file_exists() to check the availability of URLs in PHP?

Using file_exists() to check the availability of URLs in PHP may not always work as expected because it is primarily designed to check for the existence of files on the local filesystem, not remote URLs. To properly check the availability of URLs, you can use functions like curl or file_get_contents to make an HTTP request and check the response code.

function url_exists($url) {
    $headers = get_headers($url);
    return stripos($headers[0], "200 OK") ? true : false;
}

$url = "https://example.com";
if(url_exists($url)) {
    echo "URL is available";
} else {
    echo "URL is not available";
}