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 { //всё ок } 

2 answers 2

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'); 
    • Try to write more detailed answers. Explain what is the basis of your statement? - Nicolas Chabanovsky