Questa funzione restituisce una stringa vuota ogni volta che "leggo" da un socket. Per esempio, dando "http://google.it" allo script
codice:
function check_site($url1) {
$url1 = "http://$url1";
$url = parse_url($url1);
if (empty($url["port"])) $url["port"] = 80;
if (empty($url["path"])) $url["path"] = "/";
echo "Apertura $url1 con host {$url["host"]}, porta {$url["port"]}
";
$fp = @fsockopen($url["host"], $url["port"], $errno, $errstr, 30);
if (!$fp) { echo "Errore nella connessione al sito $url1 $errstr($errno)
"; }
else
{
echo "Aperto!
";
$head = "";
$httpRequest = "HEAD ". $url["path"] ." HTTP/1.1\r\nHost: ". $url["host"] ."\r\nConnection: close\r\n\r\n";
echo "Scrittura richiesta
";
fwrite($fp, $httpRequest);
echo "Lettura richiesta
";
while(!feof($fp)) $head .= fread($fp, 1024);
fclose($fp);
preg_match("=^(HTTP/d+.d+) (d{3}) ([^\r\n]*)=", $head, $matches);
if ((int)$matches[2] > 199 && (int)$matches[2] < 300 ) return "$url1 disponibile
";
else return "$url1 non disponibile
";
}
}
Mi dà sempre non disponibile, sia che esista, sia che la pagina sia realmente raggiungibile...
Inoltre se provo a stampare $matches[2] mi dà una stringa vuota. Come mai?
Il mio sito è hostato du netsons, potrebbe essere qualche valore del phpini che non lo fa andare?