What PHP function can be used to check if a link is reachable and what potential pitfalls should be considered?

To check if a link is reachable in PHP, you can use the `get_headers()` function. This function sends a HEAD request to the specified URL and returns an array of headers. One potential pitfall to consider is that the function may not work properly if the URL is not reachable or if there are network issues.

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

// Example of checking if a link is reachable
$url = 'https://www.example.com';
if(isLinkReachable($url)) {
    echo 'Link is reachable';
} else {
    echo 'Link is not reachable';
}