PHP
  Home arrow PHP arrow Page 5 - Retrieving System Information With patSysinfo
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
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? 
PHP

Retrieving System Information With patSysinfo
By: icarus, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 19
    2004-02-16


    Table of Contents:
  • Retrieving System Information With patSysinfo
  • Plug and Play
  • What's in a Name?
  • Up and at 'Em
  • Carrying the Load
  • A Nifty Device
  • Running Out of RAM
  • Mounting Up
  • Link Zone

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    Retrieving System Information With patSysinfo - Carrying the Load
    ( Page 5 of 9 )

    If it's system performance you're interested in, patSysinfo can give you that as well. Consider the getLoadAvg() method, which returns the average CPU load for the last 1, 5 and 15 minutes, or the getNumberUsers() function, which returns the number of users currently logged in to the system.


    <?php 
     
    // include class
    include("patSysinfo.php"); 
     
    // instantiate object
    $sys = new patSysinfo();
     
    // get load average
    // returns array of 3 values
    $loadArray = $sys->getLoadAvg();
     
    // get number of users
    $users = $sys->getNumberUser();
     
    // output values 
    echo "Load averages " . $loadArray[0] . " (1 min) " . $loadArray[1] . " (5 min) " . $loadArray[2] . " (15 min), $users users"; 
    ? >

    Here's the output:

    Load averages 0.01 (1 min) 2.11 (5 min) 1.43 (15 min), 12 users

    You can obtain a list of all running processes with the getProcesses() method, equivalent to the UNIX "ps" command. The list of processes is returned as an array, each element of which represents a running process and contains details on that process' owner, ID, current status and resource usage. Consider the following example, which illustrates:


    <html>
     
    <head>
     
    </head>
      
    <body>
        
    <table border="1" cellspacing="0" cellpadding="5">
          
    <tr>
            
    <td><u>Process ID</u></td>
            
    <td><u>Command</u></td>
            
    <td><u>Owner</u></td>
            
    <td><u>Terminal</u></td>
            
    <td><u>Status</u></td>
            
    <td><u>Start</u></td>
            
    <td><u>Duration</u></td>
            
    <td><u>CPU %</u></td>
            
    <td><u>Memory %</u></td>
          
    </tr>
    <?php
     
    // include class
    include("patSysinfo.php"); 
     
    // instantiate object
    $sys = new patSysinfo(); 
     
    // get process list
    $processes = $sys->getProcesses(); 
     
    foreach ($processes as $p)
    {
     
    echo "<tr>";
     
    echo "<td>" $p[pid] . "</td>";
     
    echo "<td>" $p[command] . "</td>";
     
    echo "<td>" $p[user] . "</td>";
     
    echo "<td>" $p[tty] . "</td>";
     
    echo "<td>" $p[stat] . "</td>";
     
    echo "<td>" $p[start] . "</td>";
     
    echo "<td>" $p[time] . "</td>";
     
    echo "<td>" $p[cpu] . "</td>";
     
    echo "<td>" $p[mem] . "</td>";
     
    echo "</tr>";
    }
    ? >
    </table>
    </body>
    </html>

    And here's what the output looks like:

    patSysinfo

    A variant of this is the getTopProcesses() method, which returns the same output as getProcesses() but sorts the data by CPU usage. Here's the script,


    <html>
    <head>
    </head>
    <body>
      
    <table border="1" cellspacing="0" cellpadding="5">
        
    <tr>
        
    <td><u>Process ID</u></td>
        
    <td><u>Command</u></td>
        
    <td><u>Owner</u></td>
        
    <td><u>Terminal</u></td>
        
    <td><u>Status</u></td>
        
    <td><u>Start</u></td>
        
    <td><u>Duration</u></td>
        
    <td><u>CPU %</u></td>
        
    <td><u>Memory %</u></td>
     
    </tr>
    <?php
    // include class
    include("patSysinfo.php");
     
    // instantiate object
    $sys = new patSysinfo();
     
    // get process list
    $processes = $sys->getTopProcesses(); 
     
    foreach ($processes as $p)
    {
     
    echo "<tr>";
     
    echo "<td>" $p['pid'] . "</td>";
     
    echo "<td>" $p['command'] . "</td>";
     
    echo "<td>" $p['user'] . "</td>";
     
    echo "<td>" $p['tty'] . "</td>";
     
    echo "<td>" $p['stat'] . "</td>";
     
    echo "<td>" $p['start'] . "</td>";
     
    echo "<td>" $p['time'] . "</td>";
     
    echo "<td>" $p['cpu'] . "</td>";
     
    echo "<td>" $p['mem'] . "</td>";
     
    echo "</tr>";
    }
    ? >
    </table>
    </body>
    </html>

    and here's the output:

    patSysinfo

    For script such as these, which retrieve real-time information from the system, it's a good idea to insert an auto-refresh header at the top of the page, so that the page automatically updates itself with the latest information at a user-specified interval.



     
     
    >>> More PHP Articles          >>> More By icarus, (c) Melonfire
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT