Is it advisable to use the get_headers function in PHP to determine if a webpage is still accessible?

The get_headers function in PHP can be used to determine if a webpage is still accessible by checking the response headers. It is advisable to use this function along with error handling to handle any potential issues that may arise, such as network errors or incorrect URLs.

$url = 'https://www.example.com';
$headers = @get_headers($url);

if ($headers && strpos($headers[0], '200')) {
    echo 'Webpage is accessible';
} else {
    echo 'Webpage is not accessible';
}