PDA

View Full Version : Uptime fsockopen


webhost
01-26-2002, 09:42 PM
Hi,

i`m using some php code to get servers` uptime, and here is it:


$fp = @fsockopen("12.34.56.78", "80", &$errno, &$errstr, 2);
if ($fp){
$ufuptimex=@fopen("http://12.34.56.78/get.php","r");
socket_set_timeout($ufuptimex, 2);
$ufuptime = @fgets($ufuptimex, 100);
$ufuptime = '<font color=green><b>'.$ufuptime."</b></font>";
} else {
$ufuptime = '<font color=red><b>Server out of service</b></font>';
}
@fclose($fp);


and here is my problem, if apache goes down no remote server port 80 is still opened for a default timeout (about 5 mins)..... script tryes to get uptime info and page doesnt load..... is there anyway to set fopen timeout?

webhost
01-26-2002, 10:31 PM
I have also tried to use smth like this.

$fp = fsockopen ("www.xxx.net", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br>\n";
} else {
fputs ($fp, "GET /xxx.php HTTP/1.1\r\n\r\n");
while (!feof($fp)) {
echo fgets ($fp,128);
}
fclose ($fp);
}


But I get nothing, I fear there is smth with http request that I am missing,