Dan
08-08-2005, 10:53 AM
Because I'm such a n00b at php and everything I thought you very nice fellows *wink* Would be able to help me on a little thing I'm trying to do.
I have this bit of code which is used to tell the server status in a game I run on my box. Well atm it basically pings the server on every page refresh. While that is ok and stuff I'm planning on getting mroe traffic to this script in the near future and don't want to kill the box with that kind of traffic. So what I need to do is convert this script into something I can run with a crontab to generate an html doc which I then can include in the pages it will be on.
Current Script:
<HTML>
<META http-equiv="Refresh" content="30">
<HEAD>
<TITLE>ZeRO - Server Status</TITLE>
</HEAD>
<BODY bgcolor=#FFFFFF>
<TABLE align="center" border=0 cellspacing=1 cellpadding=2 width="50%">
<TR style="font-family:Arial;font-weight:x-small;color:#000000;">
<TH>Server Name</TH><TH>Status</TH>
</TR>
<?php
error_reporting(0);
$Servers = array("Login Server"=>"IP:PORT","Char Server"=>"IP","Map Server"=>"IP:PORT","MySQL Server"=>"IP:PORT");
$cntr = 1;
while(list($ServerName,$IPnPORT)=each($Servers)){
list($IPAddress,$Port)=explode(":",$IPnPORT);
if(($cntr%2)== 1){
$bgColor = "#EDEDED";
}else{
$bgColor = "#FFFFFF";
}
if($fp=fsockopen($IPAddress,$Port,$error_no,$error _str,(float)0.5)) {
echo("
<TR align=\"center\" bgcolor=$bgColor style=\"color:#000000;font-size:small;font-family:Tahoma;\">
<TD>$ServerName </TD>
<TH style=\"color:000000;background-color:66FF00\">ONLINE</TH>
</TR>
");
fclose($fp);
}else{
echo("
<TR align=\"center\" bgcolor=$bgColor style=\"color:#000000;font-size:small;font-family:Tahoma;\">
<TD>$ServerName</TD>
<TH style=\"color:000000;background-color:FF6633\">OFFLINE</TH>
</TR>
");
}
$cntr++;
}
?>
</TABLE>
</BODY>
</HTML>
So anything would be helpful ;)
Edit: Nevermind with the help of the wonderful people on #vBorg *cough*Alan*cough*.... I was able to get this script working correctly how i wanted... thanks ;)
I have this bit of code which is used to tell the server status in a game I run on my box. Well atm it basically pings the server on every page refresh. While that is ok and stuff I'm planning on getting mroe traffic to this script in the near future and don't want to kill the box with that kind of traffic. So what I need to do is convert this script into something I can run with a crontab to generate an html doc which I then can include in the pages it will be on.
Current Script:
<HTML>
<META http-equiv="Refresh" content="30">
<HEAD>
<TITLE>ZeRO - Server Status</TITLE>
</HEAD>
<BODY bgcolor=#FFFFFF>
<TABLE align="center" border=0 cellspacing=1 cellpadding=2 width="50%">
<TR style="font-family:Arial;font-weight:x-small;color:#000000;">
<TH>Server Name</TH><TH>Status</TH>
</TR>
<?php
error_reporting(0);
$Servers = array("Login Server"=>"IP:PORT","Char Server"=>"IP","Map Server"=>"IP:PORT","MySQL Server"=>"IP:PORT");
$cntr = 1;
while(list($ServerName,$IPnPORT)=each($Servers)){
list($IPAddress,$Port)=explode(":",$IPnPORT);
if(($cntr%2)== 1){
$bgColor = "#EDEDED";
}else{
$bgColor = "#FFFFFF";
}
if($fp=fsockopen($IPAddress,$Port,$error_no,$error _str,(float)0.5)) {
echo("
<TR align=\"center\" bgcolor=$bgColor style=\"color:#000000;font-size:small;font-family:Tahoma;\">
<TD>$ServerName </TD>
<TH style=\"color:000000;background-color:66FF00\">ONLINE</TH>
</TR>
");
fclose($fp);
}else{
echo("
<TR align=\"center\" bgcolor=$bgColor style=\"color:#000000;font-size:small;font-family:Tahoma;\">
<TD>$ServerName</TD>
<TH style=\"color:000000;background-color:FF6633\">OFFLINE</TH>
</TR>
");
}
$cntr++;
}
?>
</TABLE>
</BODY>
</HTML>
So anything would be helpful ;)
Edit: Nevermind with the help of the wonderful people on #vBorg *cough*Alan*cough*.... I was able to get this script working correctly how i wanted... thanks ;)