Programming Basics
  Home arrow Programming Basics arrow Server Statistics
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Forums Sitemap 
Download TestComplete 
JMSL Numerical Library 
IBM® developerWorks
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PROGRAMMING BASICS

Server Statistics
By: Andrew Walsh
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 2
    2004-10-01

    Table of Contents:
  • Server Statistics
  • Uptime in Percentage
  • Final Script
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Server Statistics


    (Page 1 of 4 )

    If you’ve ever wanted to generate your own server statistics such as those you get with most shared hosting environments, then this tutorial is for you.

    If you have ever had shared hosting, which I am sure that most of you have, then you will probably know how these hosts pack your account with loads of server statistics tools. This is all well and good but have you ever wanted to make one for yourself? If you do then this tutorial is probably for you.

    Basic Statistics

    We will start with showing the average server load and server uptime in days. Most of this can be done with the exec() function. Basically, we will be sending the server the uptime command which will then return the information we need to form our basic server stats script.

    <?php
    $uptime 
    = @exec('uptime');
    preg_match("/averages?: ([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/",$uptime,$avgs);
    $uptime explode(' up '$uptime);
    $uptime explode(','$uptime[1]);
    $uptime $uptime[0].', '.$uptime[1];
    $start=mktime(00011date("Y"), 0);
    $end=mktime(000date("m"), date("j"), date("y"), 0);
    $diff=$end-$start;
    $days=$diff/86400;
    $percentage=($uptime/$days) * 100;
    $load=$avgs[1].",".$avgs[2].",".$avgs[3]."";
    echo 
    'Average Load: '.$load;
    echo 
    'Uptime: '.$uptime;
    ?>

    If you where to run that script on your website then you would get two statistics back, the server load and then the uptime in days. This may seem very simple. Well, to be honest this whole tutorial is quiet easy actually. In the next sections we will be applying the same principles as this code. In the next section we will be looking at how to show a percentage of how much of the year the server has been online. The basis is already there in this script.

    More Programming Basics Articles
    More By Andrew Walsh


       · For human readablity let's throw in a line break between the existing line 14 and...
     

    PROGRAMMING BASICS ARTICLES

    - Loops and PHP Decision Making
    - Operators, Conditionals, and PHP Decision-Ma...
    - PHP Decision-Making
    - Coding
    - Server Statistics
    - Looping in PHP
    - Cookies in PHP
    - Working with text files
    - Beginning Object Oriented Programming in PHP
    - A Tour of Decision Making Structures in PHP
    - PHP Strings Primer
    - PHP Control Structures
    - Intro to Vim
    - Reading Directorys with PHP
    - An Overview of Arrays in PHP





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT