Recommend this page to a friend! |
Download .zip |
Info | View files (6) | Download .zip | Reputation | Support forum (1) | Blog (1) | Links |
Ratings | Unique User Downloads | Download Rankings | ||||
Not enough user ratings | Total: 178 | All time: 8,734 This week: 673 |
Version | License | PHP version | Categories | |||
system-resources 1.0.0 | Custom (specified... | 5 | PHP 5, System information, Windows, H... |
Description | Author | |||
This package can get values of the current computer devices. Innovation Award
|
It 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:
- Simple Raspberry pi (B + 512MB 700 MHz ARM11) with Raspbian Lite PHP7.3 (i love this gadgets) :heart_eyes:
- VirtualBox Ubuntu Server 20.04.2 LTS (Focal Fossa) with PHP7.4.3
# 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
require_once( 'system_resources.class.php' );
# BASIC USAGE:
- Create the variable with class system resources:
$sys_res = new system_resources();
- Print Total Memory space:
$MemResources = $sys_res->Resources->fGetMemResources( );
echo $MemResources['MemTotal'];
$sys_res = new system_resources( );
Example:
$sys_res = new system_resources();
GET OPERATING SYSTEM WINDOWS OR GNU/LINUX:
By default, we ask for some string in PHP version. if 'WIN' string is in the string, then assume Operating System is Windows, else we assume is GNU/Linux
$sys_res->IsWindows;
Example:
if($sys_res->IsWindows){
echo 'Windows Server';
} else {
echo 'Linux Server';
}
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:
$TotalHdBytes = $sys_res->Resources->fGetTotalHD();
$TotalHd = $sys_res->convert( $TotalHdBytes ); // return 2tb, for example
GET CPU LOAD AVERAGE ( Only GNU/Linux ):
Get the CPU Average load over the last 1, 5 and 15 minutes, respectively
$sys_res->Resources->fgetCPUAvgLoad(){
Example:
$loadavg = $sys_res->Resources->fgetCPUAvgLoad()
$Cpu1minute = $loadavg[0];
$Cpu5minutes = $loadavg[1];
$Cpu15minutes = $loadavg[2];
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:
echo $sys_res->Resources->fgetCPULoad().'% of CPU usage';
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:
$MemResources = $sys_res->Resources->fGetMemResources();
echo 'Total Mem: '.$MermResources['MemTotal'].PHP_EOL;
echo 'Free Mem: '.$MermResources['MemFree'].PHP_EOL;
echo 'Available Mem: '.$MermResources['MemAvailable'].PHP_EOL;
Get total HD Capacity (in bytes)
$sys_res->Resources->fGetTotalHD();
Example:
echo $sys_res->Resources->fGetTotalHD().' bytes';
Get Free HD Capacity (in bytes)
$sys_res->Resources->fGetFreelHD();
Example:
echo $sys_res->Resources->fGetFreelHD().' bytes';
Get used HD Capacity (in bytes)
$sys_res->Resources->fGetUsedHD();
Example:
echo $sys_res->Resources->fGetUsedHD().' bytes';
Get a string uptime.
$sys_res->Resources->fGetUptime( );
Example:
echo $sys_res->Resources->fGetUptime( );
Get CPU temperature in ºC.
$sys_res->Resources->fGetCPUTemperature( );
Example:
echo 'CPU Temperature: '.$sys_res->Resources->fGetCPUTemperature( ).'ºC';
Get GPU temperature in ºC.
$sys_res->Resources->fGetGPUTemperature( );
Example:
echo 'GPU Temperature: '.$sys_res->Resources->fGetGPUTemperature( ).'ºC';
Get OS version.
$sys_res->Resources->fGetOSVersion( );
Example:
echo 'OS Version: '.$sys_res->Resources->fGetOSVersion( );
Get hardware version.
$sys_res->Resources->fGetHWVersion( );
Example:
echo 'HW Version: '.$sys_res->Resources->fGetHWVersion( );
Get Release Distribution.
$sys_res->Resources->fGetReleaseDistrib( );
Example:
echo 'Release Distribution: '.$sys_res->Resources->fGetReleaseDistrib( );
Get Number of CPU'S.
$sys_res->Resources->fGetNumCPUs( );
Example:
echo 'Number of CPU's: '.$sys_res->Resources->fGetNumCPUs( );
# 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
Files |
File | Role | Description |
---|---|---|
LICENSE | Lic. | License text |
README.md | Data | Read me |
resources.class.php | Class | Class source |
resources_linux.class.php | Class | Class source |
resources_windows.class.php | Class | Class source |
system_resources.class.php | Class | Class source |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
User Comments (1) | |||||
|
Applications that use this package |
Used to control CPU temperature in Machine Learning Processes |
If you know an application of this package, send a message to the author to add a link here.
Related pages |
Author blog inform of Launch PHP System Resources |