I am designing a utility for my end-user where he can bookmark a website, but before bookmarking the website I built a PHP function to check the website availability status and notify about the downtime if the website is down. The following code snippets are used to check the domain availability using PHP cURL and show the status of the website.
the issue that I am facing is the response always comes as false. I don't know the reason. any advice?
<?php
$URL = 'https://www.google.com';
if(isSiteAvailible($URL)){
echo 'The website is available.';
}else{
echo 'Woops, the site is not found.';
}
function isSiteAvailible($url){
// Check, if a valid url is provided
if(!filter_var($url, FILTER_VALIDATE_URL)){
return false;
}
// Initialize cURL
$curlInit = curl_init($url);
// Set options
curl_setopt($curlInit,CURLOPT_CONNECTTIMEOUT,10);
curl_setopt($curlInit,CURLOPT_HEADER,true);
curl_setopt($curlInit,CURLOPT_NOBODY,true);
curl_setopt($curlInit,CURLOPT_RETURNTRANSFER,true);
// Get response
$response = curl_exec($curlInit);
// Close a cURL session
curl_close($curlInit);
return $response?true:false;
}
?>
When I added curl_error()
it tells me
"Recv failure: Connection was reset"
Why?