Recommend this page to a friend! |
Classes of Rafael Martin Soto | PHP System Resources | README.md | Download |
|
Downloadsystem-resources. A class to get the hardware resourcesWe can get CPU load, CPU/GPU temperature, free/used memory & Hard disk. Written in PHPIt is a library for get system resources. Some times, as we need to control CPU temperature when doing hard tasks as machine learning (deep learning). When we want to do Multithread programming, it would be convenient to know a priory the number of CPU's we can use. I wrote this library to help not only with the CPU temperature or to get the number of CPU'S, also to get all the rest of system resources. Some systems need to get access to some files to read this values, then, a production web server, perhaps is not the best way to access these resources. It is recommended to use a CLI environment, and if we still cannot access the resources, we may have to run the PHP application with a user with permissions to those resources or use SUDO on GNU / Linux systems. The library has been written to obtain the maximum number of resources available on both GNU / Linux servers and Windows, but access to parts of the system is highly restricted, so it may not work correctly in all methods. An attempt has been made to maintain maximum compatibility with return values on both GNU / Linux and Windows. Windows has some other values that we can access, but in different versions of OS we will get some different results. # REQUERIMENTS: - A minimum (minimum, minimum, minimum requeriments is needed). Tested on:
# FILES: There are 4 basic files: system_resources.class.php -> Master class. This file is the main file that you need to include in your code. This file includes inside resources.class.php resources.class.php -> Standard system resources class resources_linux.class.php -> Resources for GNU/Linux systems class resources_windows.class.php -> Resources for Windows systems class # INSTALLATION: A lot of easy :smiley:. It is written in PURE PHP. Only need to include the files. Tested on basic PHP installation
# BASIC USAGE: - Create the variable with class system resources:
- Print Total Memory space:
RESUME OF METHODS:
$sys_res = new system_resources( ); Example:
$sys_res->IsWindows; Example:
This extra method helps to get results more human readable. It returns a value in Bytes, Kbytes, Mbytes, Gbytes, Tbytes, Pbytes. You pass to the method the value in integer Bytes. $sys_res->convert( INT ); Example:
$sys_res->Resources->fgetCPUAvgLoad(){ Example:
The system needs to calculate the difference between CPU load in a periode of 1 second. Then this method takes 1 second to execute. Returns a percentage of usage $sys_res->Resources->fgetCPULoad(); Example:
Get the memory available, used, free, .... In linux you have a lot of other values. See resources_linux.class.php to see all of possibilities $MemResources = $sys_res->Resources->fGetMemResources(); Example:
Get total HD Capacity (in bytes) $sys_res->Resources->fGetTotalHD(); Example:
Get Free HD Capacity (in bytes) $sys_res->Resources->fGetFreelHD(); Example:
Get used HD Capacity (in bytes) $sys_res->Resources->fGetUsedHD(); Example:
Get a string uptime. $sys_res->Resources->fGetUptime( ); Example:
Get CPU temperature in ºC. $sys_res->Resources->fGetCPUTemperature( ); Example:
Get GPU temperature in ºC. $sys_res->Resources->fGetGPUTemperature( ); Example:
Get OS version. $sys_res->Resources->fGetOSVersion( ); Example:
Get hardware version. $sys_res->Resources->fGetHWVersion( ); Example:
Get Release Distribution. $sys_res->Resources->fGetReleaseDistrib( ); Example:
Get Number of CPU'S. $sys_res->Resources->fGetNumCPUs( ); Example:
# FUTURE PLANS 1) GET SINGLE CPU TEMPERATURE We can get the CPU temperature of a single CPU. Next version will have the option to get the Average temperature of all CPU's or the total CPU temperature of a single CPU. 2) CREATE EMPTY METHODS ON WINDOWS CLASS FOR COMPATIBILITY WITH GNU/LINUX METHODS Most of functions used in GNU/Linux systems is not defined in Windows class. Next step will be create it with null return or something else. In this way, if we call a GNU/Linux function that does not exist in Windows, the system will not fail. Of course. You can use it freely :vulcan_salute::alien: By Rafa. Developed and released by https://bio-farma.es @link https://bio-farma.es @author Rafael Martin Soto @author {@link http://www.inatica.com/ Inatica} @blog {@link https://rafamartin10.blogspot.com/ Rafael Martin's Blog} @since July 2021 @version 1.0.0 @license GNU General Public License v3.0 |