1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| function monTestPage($site, $page, $timeout = 10){
list($usec, $sec) = explode(" ", microtime());
$t0 = ((float)$usec + (float)$sec);
$fp = fsockopen($site, 80, $errno, $errstr, $timeout);
if (!$fp) {
$return['msg'] = 'Impossible de se connecter au domaine '.$site.'<br />';
} else {
$return['serveur'] = 'Connexion serveur OK';
$header = "GET $page HTTP/1.1\r\n";
$header .= "Host: $site\r\n";
$header .= "Connection: Close\r\n\r\n";
fputs($fp, $header);
stream_set_timeout($fp, $timeout);
$reponse = fgets($fp, 128);
list($usec, $sec) = explode(" ", microtime());
$t1 = ((float)$usec + (float)$sec);
$info = stream_get_meta_data($fp);
if ($info['timed_out']) {
$return['msg'] = "Le délai de réponse de la page ".$site.$page.
' a dépassé le timout de '.$timeout.' sec.';
}else{
$return['reponsePage'] = $reponse;
$return['tempsReponse'] = $t1 - $t0;
}
fclose($fp);
}
return $return;
}
$resultat = monTestPage ('172.28.45.43', 'file://172.28.45.43/chemin/plop.sxw', 100);
print_r($resultat); |
Partager