Home arrow PHP arrow Page 7 - Retrieving System Information With patSysinfo

Running Out of RAM - PHP

Linux file structure contains within it a special area called /proc. Now, some believe that there's black magic in that directory. For those who know better than to fear the /proc, there awaits much good magic, in the form of server info. Looking for a way to retrieve real-time server information and display it to users in your Web application? Today's your lucky day! Take a look at the patSysinfo PHP class, which lets you do that and a whole lot more.

TABLE OF CONTENTS:
  1. Retrieving System Information With patSysinfo
  2. Plug and Play
  3. What's in a Name?
  4. Up and at 'Em
  5. Carrying the Load
  6. A Nifty Device
  7. Running Out of RAM
  8. Mounting Up
  9. Link Zone
By: icarus, (c) Melonfire
Rating: starstarstarstarstar / 19
February 16, 2004

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Detailed memory usage can be obtained via the very cool getMem() method, which provides data on current memory usage and available resources. Take a look:


<?php 
 
// include class
include("patSysinfo.php"); 
 
// instantiate object
$sys = new patSysinfo(); 
 
// get memory information
$mem = $sys->getMem(); 
 
// print data
print_r($mem); 
 
? >

Here's the output:

Array
(
    [0] => Array
        (
            [type] => mem
            [total] => 123.73 MByte
            [used] => 36.02 MByte
            [free] => 87.71 MByte
            [shared] => 0.00 Byte
            [buffers] => 1.56 MByte
            [cached] => 22.25 MByte
            [percent] => 10
        )

    [1] => Array
        (
            [type] => swap
            [total] => 0.00 Byte
            [used] => 0.00 Byte
            [free] => 0.00 Byte
            [shared] => NA
            [buffers] => NA
            [cached] => NA
            [percent] => 0
        )

)

This usually looks a lot nicer when it's properly formatted into an HTML table, as in this revision of the script above:


<html>
<head>
</head>
<body>
  
<table border="1" cellspacing="0" cellpadding="5">
   
<tr>
      
<td><u>Type</u></td>
      
<td><u>Total memory</u></td>
      
<td><u>Used memory</u></td>
      
<td><u>Free memory</u></td>
      
<td><u>Shared</u></td>
      
<td><u>Buffers</u></td>
      
<td><u>Cached</u></td>
    
</tr
 
<?
php
 
// include class
include("patSysinfo.php"); 
 
// instantiate object
$sys = new patSysinfo(); 
 
// get memory information
$mem = $sys->getMem(); 
 
// output memory information
foreach($mem as $m)
{
 echo "<tr>";
 echo "<td>" . $m['type'] . "</td>";
 echo "<td>" . $m['total'] . "</td>";
 echo "<td>" . $m['used'] . "</td>";
 echo "<td>" . $m['free'] . "</td>";
 echo "<td>" . $m['shared'] . "</td>";
 echo "<td>" . $m['buffers'] . "</td>";
 echo "<td>" . $m['cached'] . "</td>";
 echo "</tr>";
}
 
? >
 
</
body>
</html>

And here's the output:

patSysinfo



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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: