Programming Basics
  Home arrow Programming Basics arrow Page 2 - 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  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
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 / 4
    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 - Uptime in Percentage


    (Page 2 of 4 )

    If you looked at the last code you saw two redundant and useless date() functions. Well in this section they will be used to work out what percentage of the year so far the server has been online. All we do is add a line to calculate the percentage uptime.

    Here is the whole block of code to work out the percentage of the year so far.

    <?php
    $start
    =mktime(00011date("Y"), 0);
    /* Make date 1/1/(current year) */
    $end=mktime(000date("m"), date("j"), date("y"), 0);
    /* Make todays date */
    $diff=$end-$start;
    $days=$diff/86400;
    $percentage=($uptime/$days) * 100;
    /* Work out percentage */
    echo $percentage;
    /* Print out percentage */
    ?>

    This could be used for anything, firstly we use $start and mktime to acquire the number of seconds since 1/1/(the current year) and then we aquire today’s date using the same function. To work out how long in seconds the server has been online we take $start from $end. Now to work out the days we divide the result by 86400 and we will get a number of days which then we divide by $uptime (obtained from the first code snippet) and multiply by 100 to get a percentage. Simple wasn’t it?

    Next we will work on a more complex version, this will include listing of server variables like the server name, IP, port, software and gateway.

    More Programming Basics Articles
    More By Andrew Walsh


       · For human readablity let's throw in a line break between the existing line 14 and...
       · Personall I use <a href="http://status2k.com">Server Statistics - Status2k</a>, it's...
     

    PROGRAMMING BASICS ARTICLES

    - PHP: Hypertext Preprocessor: What is it?
    - 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





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek