FastSitePHP\Environment\System

System and OS Info

Source Code

GitHub

Exemple de Code

Get Environment and System Info

// Create an Environment System Object
$sys = new \FastSitePHP\Environment\System();

// Get an array of basic information related to the Operating System
// [ 'OS Type', 'Version Info', 'Release Version', 'Host Name', 'CPU Type' ]
$os_info = $sys->osVersionInfo();

// Get a text string of detailed system info using one of the following commands:
// - Linux   = File: '/etc/os-release'
// - FreeBSD = uname -mrs
// - IBM AIX = uname -a
// - Mac     = system_profiler SPSoftwareDataType SPHardwareDataType
// - Windows = ver
$info = $sys->systemInfo();

// Get an array of information related to free, used, and total space for
// a filesystem drive or disk partition. This function allows for specific
// drives or partitions to be specified.
// - *nix    = $sys->diskSpace('/dev/disk0')
// - Windows = $sys->diskSpace('C:')
$disk_space = $sys->diskSpace();

// Windows only function that returns an array of drive letters
// mapped to the server. Returns an empty array for other OS's.
$mapped_drives = $sys->mappedDrives();

Methods

osVersionInfo()

Returns an array of basic information related to the Operating System. This typically includes human readable information such as the OS Version. On some older UNIX platforms this function may instead return the OS that PHP was built on but this is not expected on Windows, Linux, or Mac.

For detailed system information see the function [systemInfo()] in this class. See also [\FastSitePHP\Net\Config->fqdn()]

Keys in the Returned Array:
    [ 'OS Type', 'Version Info', 'Release Version', 'Host Name', 'CPU Type' ]

Returns: array

systemInfo()

Return a string of System Info from the OS. If System info can't be determined then null will be returned. This function works with various OS's including Windows, Mac, and recent versions of Linux. It runs the following commands:

    Linux:   cat /etc/os-release
    Windows: ver
    Mac:     system_profiler SPHardwareDataType SPSoftwareDataType
    FreeBSD: uname -mrs
    IBM AIX: uname -a

If running on Linux and the file [/etc/os-release] doesn't exist system info can possibly be obtained from one of the following commands:

    lsb_release -a
    cat /etc/*-release
    cat /etc/*_version

On Windows detailed info may be obtained by using the command [systeminfo] instead however calling [systeminfo] often takes 10 - 30 seconds to run.

FreeBSD also supports the command [freebsd-version] which will likely include the same info as this function.

For IBM iSeries (AS/400) Newer versions of the OS inlude commands [lscfg, oslevel, prtconf] however often the OS is not updated so this function simply returns [uname -a].

Returns: string | null

diskSpace($drive = null)

Return an array of information related to free, used, and total space for a filesystem drive or disk partition. The returned values include the size calculated in Bytes, Megabytes, Gigabytes, and Percent. If this function is called with no parameters then the default drive or disk will be used. To get info for specific drive call this function with the disk partition (Mac, Linux) or Drive Letter (Windows), for example '/dev/disk0' or 'D:'. Internally this function uses PHP functions [disk_free_space()] and [disk_total_space()].

Keys in the Returned Array:
  [ 'Drive',
    'Free Space Bytes', 'Free Space MB', 'Free Space GB', 'Free Space Percent',
    'Used Space Bytes', 'Used Space MB', 'Used Space GB', 'Used Space Percent',
    'Total Space Bytes', 'Total Space MB', 'Total Space GB' ]

Returns: array

mappedDrives()

Windows only function that returns an array of drive letters mapped to the server. For example if the server running PHP has drives C, D, and Z mapped then this function will return array('C:', 'D:', 'Z:'). I this function is called from a Non-Windows computer then an empty array will be returned.

Returns: array