?
Solved

System Status Page

Posted on 2004-11-29
8
Medium Priority
?
220 Views
Last Modified: 2006-11-17
Hi guys,

Im fairly new to php and I need your expertise!!  I have a php script that checks (pings) a server.  I do this 3 times for 3 differernt servers.  What I need to do is create a "general status page". I was thinking of this...When any of the 3 servers are down, a file is written to the web server.  Then on the general status page I could have something that checks for the existence of that one file.  If it exists then it will display a particular picture, if it doesnt exisit it will display another picture.  This means that should one server be down, the file will be created and the "general" status indicator will change.  Hope that makes sense and hope someone can help!!

Thanks!
0
Comment
Question by:NovoNordisk
  • 2
  • 2
  • 2
6 Comments
 
LVL 9

Expert Comment

by:gruntar
ID: 12694605
You could create a simple table in your database with server names and status column. Then, when checking status you could just change status of particular server if needed.

To show status of those servers, you would just fetch server names and show proper images.

Hope that helps
0
 
LVL 8

Author Comment

by:NovoNordisk
ID: 12694621
Good idea but I dont really want to use a DB.  I already have a script that displays the status of given servers, but I just need to generalise the status of them.  So if when one of those servers are down I create a file, then I can check for the existance of that file - somehow!!!
0
 
LVL 9

Expert Comment

by:gruntar
ID: 12694839

to check existance of file do it like this

if (file_exists($filename)) {
   // do something
}

Why are you trying to do this "hard" way?

>> So if when one of those servers are down I create a file..
Why only then? why don't you have one file for each server and then you just replace status. Do you delete those files?

Give us more info..
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Author Comment

by:NovoNordisk
ID: 12694913
I dont see it as being a "hard" way.  All I want is a basic status page and an advanced one.  If one of the checks on the advanced page fails, then that should affect the basic status page.  Ive just worked out how to create a file, delete it and check it, and it works OK, so unless you have a better way of doing this I might leave it as this!?
0
 
LVL 27

Accepted Solution

by:
Diablo84 earned 2000 total points
ID: 12695007
You could take an approach line this (for the sake of example i have just used fsockopen with 3 random domains).

Writing to the file:

$server[1] = (@fsockopen("www.google.com",80)) ? "Up" : "Down";
$server[2] = (@fsockopen("www.experts-exchange.com",80)) ? "Up" : "Down";
$server[3] = (@fsockopen("www.php.net",80)) ? "Up" : "Down";

foreach ($server as $key => $var) {
 $filecontents[] = "$Key|$var";
 fclose($server[$key]);
}

$hanlde = fopen("yourstatsfile.txt","w");
fwrite($handle,implode("\n",$filecontents));
fclose($handle);

Displaying status:

if (file_exists("yourstatsfile.txt")) {
 $contents = file("yourstatsfile.txt");
 foreach ($contents as $line) {
  $parts = explode("|",$line);
  $status ($parts[1] == "Up") ? "Online" : "Offline";
  echo "SERVER: ".$parts[0]." is ".$status."<br>\n";
 }
}
0
 
LVL 27

Expert Comment

by:Diablo84
ID: 12695026
or to use an image, instead of:

  $status ($parts[1] == "Up") ? "Online" : "Offline";
  echo "SERVER: ".$parts[0]." is ".$status."<br>\n";

use something like:

  $status ($parts[1] == "Up") ? "image1.jpg" : "image2.jpg";
  echo "<img src=\"$status\"><br>";

The method i have shown tracks all servers, so the log file might contain something like

1|UP
2|Down
3|Up

Then when it comes to displaying the status the check is made for all of them, this behaviour can be modified if needed.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

579 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question