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

Up and at 'Em - 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.

  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



How about finding out how long it's been since the system's last reboot? Well, patSysinfo allows you to duplicate the "uptime" command with its getUptime() function. Take a look:

// include class
// instantiate object
$sys = new patSysinfo();
// get uptime
$uptime = $sys->getUptime(); 
// output values 
echo "Last reboot was " . $uptime['days'] . " days, " . $uptime['hours'] .
" hours and " . $uptime['mins'] . " minutes ago";
? >

The getUptime() method returns the time since the system's last reboot as an associative array with keys "days", "mins" and "hours". This can then easily be formatted into a readable string, as above. Here's the output:

Last reboot was 0 days, 1 hours and 43 minutes ago

Want to know a little bit more about the hardware and software running on the system? Take a look at the getKernelVersion() and getCpu() functions, which return the current kernel version and processor details respectively.

// include class
// instantiate object
$sys = new patSysinfo(); 
// get kernel version
$kv = $sys->getKernelVersion(); 
// get processor information
$cpuArray = $sys->getCpu(); 
// extract model, speed, cache etc
$model = $cpuArray[0]['model'];
$speed = $cpuArray[0]['mhz'];
$cache = $cpuArray[0]['cache'];
$mips = $cpuArray[0]['bogomips']; 
// output values 
echo "Kernel $kv running on a $model at $speed MhZ ($cache cache, $mips bogomips)"; 
? >

The getCpu() function, in particular, deserves closer attention. This function returns an array, each element of which is itself an associative array representing one of the processors in the CPU (most often, you will have a single-processor CPU and therefore only one element in this array). The associative array for each processor itself contains information on the processor name, clock speed, cache size and other relevant values.

Here's the output:

Kernel 2.4.20 running on a Pentium III (Katmai) at 451.03 MhZ (512 KB cache, 897.84 bogomips)

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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- 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: