It is necessary to check whether the site is available. I check it like this, is this a normal solution?
$port = 80; $host = 'ya.ru'; $fp = fsockopen($host,$port); if(!$fp){ //не доступен } else { //всё ок } It is necessary to check whether the site is available. I check it like this, is this a normal solution?
$port = 80; $host = 'ya.ru'; $fp = fsockopen($host,$port); if(!$fp){ //не доступен } else { //всё ок } cURL solved the problem, there was an example on the forum, something like
$domain = 'ya.ru'; //инициализация curl $curlInit = curl_init($domain); curl_setopt($curlInit,CURLOPT_CONNECTTIMEOUT,10); curl_setopt($curlInit,CURLOPT_HEADER,true); curl_setopt($curlInit,CURLOPT_NOBODY,true); curl_setopt($curlInit,CURLOPT_RETURNTRANSFER,true); //получение ответа $response = curl_exec($curlInit); curl_close($curlInit); $response = $response ? $response = 'всё ок' : $response = 'недоступен'; echo $response; Open socket does not help, get the content of the site, and on it you will determine whether it is available or not.
$data = file_get_contents('http://ya.ru'); Source: https://ru.stackoverflow.com/questions/580617/
All Articles