Programming Basics

  Home arrow Programming Basics arrow Page 2 - Server Statistics
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

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    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

    blog comments powered by Disqus

    PROGRAMMING BASICS ARTICLES

    - Control Flow Constructs
    - More Time Manipulation with PHP
    - Validating and Manipulating Dates with PHP
    - Using the Date Constructor in PHP
    - Calendar Construction with PHP
    - PHP`s Calendar Package
    - Getting Modified Versions and Correct Dates ...
    - Combining Date Functions in PHP
    - Using PHP for Date and Time in Programming
    - More Exception Handling with PHP
    - Exception Handling in PHP
    - Error Logging and Handling Exceptions
    - Configuration Directives for Error and Excep...
    - Error and Exception Handling
    - Python Modules for Games


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 9 - Follow our Sitemap