System Status Page

Posted on 2004-11-29
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!!

Question by:NovoNordisk
    LVL 9

    Expert Comment

    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
    LVL 8

    Author Comment

    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!!!
    LVL 9

    Expert Comment


    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..
    LVL 8

    Author Comment

    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!?
    LVL 27

    Accepted Solution

    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("",80)) ? "Up" : "Down";
    $server[2] = (@fsockopen("",80)) ? "Up" : "Down";
    $server[3] = (@fsockopen("",80)) ? "Up" : "Down";

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

    $hanlde = fopen("yourstatsfile.txt","w");

    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";
    LVL 27

    Expert Comment

    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


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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
    Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    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…

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now