View Full Version : Uptime fsockopen

26 Jan 2002, 23:42

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

$fp = @fsockopen("", "80", &$errno, &$errstr, 2);
if ($fp){
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>';

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?

27 Jan 2002, 00:31
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,