Answer the question
In order to leave comments, you need to log in
What are the quick and reliable ways to check the availability of a site in PHP?
It is required to check the site by url whether it is available now or not.
Now I'm using this script:
function accessSite($url) {
if (preg_match('/[^0-9a-z-_A-Z:\.]/is', $url)!=0) {
include("modules/idna_convert.class.php");
$IDN=new idna_convert(array('idn_version' => '2008'));
$url=$IDN->encode($url);
}
@$status=get_headers($url);
if ($status) {
if (in_array("HTTP/1.1 200 OK", $status) || in_array("HTTP/1.0 200 OK", $status)) return true;
}
return false;
}
Answer the question
In order to leave comments, you need to log in
It is necessary to determine the accessibility criteria:
1) exceeding the connection timeout;
2) getting some expected response via http.
The request can be made via curl and set a timeout in it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question