Check if websites are working, php

Asked

Viewed 181 times

0

Hi, I’m wanting to do a check on several links, check if they are working, I’m using the code below for this, but it only works when I test locally on the server of my pc, when I raise it to the hosting server does not work properly. On the hosting server links that have type ports http://179.106. 7.93:5656/System, does not show as Operative even if it is. They could help me, or even give me another strategy, because what I’m using takes a long time to load. To 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");

}

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");

    }
}
  • hi friend, occurred the same problem, in my local network works, showing really who is active, but when I go up to hosting does not work

Browser other questions tagged

You are not signed in. Login or sign up in order to post.