Jump to content

Problem With Server Status Script


Recommended Posts

I keep getting frustrated with my server status script which checks my 2 remote servers like IRC and my Game server statuses.

if 1 of those servers are offline the script keeps trying to reach it and site wont load until it reaches the server. So i would want a time out feature to my status checker so it kills the check if it takes too long and then returns offline status.

Here is the script:

 

 <?php

 // Status By NecroNet
 // Config, Edit this!	(You could add this to your config file)

 $IP = "irc.domain.tld";		 //Server IP-address
 $Port = "3306";		 //Port for server (standard is 25565)

 $title =  "IRC-Server";   // Name of Server
 $flash_file  = "statusbar.swf"; // Location of the flash file



 // Don't edit anything under this!

$p = "$title";
	$fp = @fsockopen($IP, $Port, $errno, $errstr);
if (!$fp) {
	$t= "Offline";
$bgcolor = "#FF0000";
	} else {
	$t= "Online";
$bgcolor = "#00FF00";
	}
	@fclose($fp);
 echo "<embed src='".$flash_file."?t=".$p."&m=".$t."' quality='high' bgcolor='".$bgcolor."' width='176' height='60'></embed>";


   ?>

php side checks the server and then loads flash box saying is it online or not.

Link to comment
Share on other sites

Here's a way I'm more familiar with using cURL:

 

<?php
$url = "http://helionet.org/";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);

# here's where you set number of seconds before time out
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);

$content = curl_exec($ch);
$header = curl_getinfo($ch);
$time = $header['connect_time'];
$httpcode = $header['http_code'];
curl_close($ch);

# if http code is good return site is up
if($httpcode >= 200 && $httpcode < 303)
{
echo "Site is up and working!<br>";
}
else
{
echo "Site is down!<br>";
}

# if connection time is 0 return connection timed out
if ($time == "0")
{
echo "Connection Timed Out After 15 Seconds!";
}
?>

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...