Check if sites are working, php

0
Hi, I'm trying to check several links, check if they are working, I'm using the code below for this, but it only works when I test locally on my pc server, when I upload it to the hosting server it does not work properly . On the hosting server the links that have ports type link , does not show how even being operational. They could help me, or even give me another strategy, because what I'm using takes a lot of time to load. I'm using Mysql database to store links

function url_existe($url1) {
    $ch = curl_init($url1);
    curl_setopt($ch, CURLOPT_NOBODY, true);
    curl_exec($ch);
    $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    return ($code == 200); // verifica se recebe "status OK"
}

while($lista_url_a = mysql_fetch_assoc($lista_url)) {
    $url = $lista_url_a['url'];
    $id_url = $lista_url_a['id'];


$url2 = $url;
if (url_existe($url2))
        $atualiza_url = mysql_query("update url set status = 'OPERANTE' where id= $id_url");
    else
        $atualiza_url = mysql_query("update url set status = 'INOPERANTE' where id= $id_url");

}
    
asked by anonymous 27.09.2018 / 22:14

1 answer

1

Try the following function

function get_http_response_code($domain1) {
    $headers = get_headers($domain1);
    return substr($headers[0], 9, 3);
}    

function url_existe($domain1){

    $get_http_response_code = get_http_response_code($domain1);

    if ( $get_http_response_code == 200 ) {
       return "OPERANTE";
    } else {
       return "INOPERANTE";
    }
}



while($lista_url_a = mysql_fetch_assoc($lista_url)) {
    $url = $lista_url_a['url'];
    $id_url = $lista_url_a['id'];


    $url2 = $url;
    if (url_existe($url2) == "OPERANTE"){
        $atualiza_url = mysql_query("update url set status = 'OPERANTE' where id= $id_url");
    }else{
        $atualiza_url = mysql_query("update url set status = 'INOPERANTE' where id= $id_url");

    }
}
    
27.09.2018 / 22:48