Retrieving System Information With patSysinfo - Running Out of RAM
(Page 7 of 9 )
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:

Next: Mounting Up >>
More PHP Articles
More By icarus, (c) Melonfire