how to correctly ping php?

1

I'm currently building a tool to test the availability of a website, I'm doing it in php and it works great

<?php
function pingDomain($domain){
    $starttime = microtime(true);
    $file      = @fsockopen ($domain, 80, $errno, $errstr, 10);
    $stoptime  = microtime(true);
    $status    = 0;

    if (!$file) $status = -1;  // Site is down
    else {
        fclose($file);
        $status = ($stoptime - $starttime) * 1000;
        $status = floor($status);
    }

    if ($status <> -1) {
        return true;
    }

    return false;

}
//llamando a la funcion
if (pingDomain('www.dominio.com')) {
    echo 'ON';
} else {
    echo 'OFF';
}

but as you will see it only works with sites

  

www.dominio.com

but it does not work with directories,

  

www.dominio.com/seccionaparte

What changes could you make so that you can test that type of url? thanks in advance

If it's easier with another language I accept suggestions ...

    
asked by ragnamex 19.04.2018 в 23:11
source

0 answers