WordPress Code Snippets

A fresh mix of code snippets and tutorials

PHP Get Server Information

262

Here are some scrap PHP scripts leftover from my work on Dashboard Widgets Suite. These functions were considered specifically for use with the System Information Widget, and provide a variety of details about the current server configuration and software setup.

Disclaimer

Before trying any of these scripts, keep in mind that they may need tweaking in order to support a wider range of servers, software, and scenarios. For example, I develop on Linux machines and never really bother testing anything on Windows. I know, I’m a horrible person.

Also keep in mind that these functions are very bare-bones, and are meant as starting points to get you going with your development efforts. That is, they are great for getting started and generating ideas, not for plug-n-play production deployment.

So with those points in mind, here is a growing collection of functions for getting all sorts of useful server information and data.

Get system load as percentage

This function returns the system load as a percentage:

Note: you can use the next function to pass the number of system cores to this function.

Get the number of system cores

This function returns the number of system cores:

Get the number of HTTP connections

This function returns the number of PHP connections:

Get server memory usage

This function returns the server memory usage as a percentage:

Get current disk usage

This function returns the amount of disk usage as a percentage:

Get server uptime

This function returns the server uptime:

Get the kernel version

This function returns the kernel version:

Get the number of processes

This function returns the number of running processes:

Get current memory usage

This function returns the current memory usage:


Show Support

Like our new Facebook Page to show support!