-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSysInfo.php
More file actions
232 lines (208 loc) · 6.28 KB
/
Copy pathSysInfo.php
File metadata and controls
232 lines (208 loc) · 6.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<?php
namespace futuretek\shared;
/**
* Class SysInfo
*
* @package futuretek\shared
* @author Lukas Cerny <lukas.cerny@futuretek.cz>
* @license Apache-2.0
* @link http://www.futuretek.cz
*/
class SysInfo
{
/**
* Get system load information
*
* @return array Load in last 1, 5 and 10 minutes
* @static
*/
public static function loadAverage()
{
return explode(' ', file_get_contents('/proc/loadavg'));
}
/**
* Get information about memory
*
* @return array Get associative array with information about memory. Array key can be:
* <ul>
* <li>MemTotal</li>
* <li>MemFree</li>
* <li>Buffers</li>
* <li>Cached</li>
* <li>SwapCached</li>
* <li>Active</li>
* <li>Inactive</li>
* <li>Active(anon)</li>
* <li>Inactive(anon)</li>
* <li>Active(file)</li>
* <li>Inactive(file)</li>
* <li>Unevictable</li>
* <li>Mlocked</li>
* <li>SwapTotal</li>
* <li>SwapFree</li>
* <li>Dirty</li>
* <li>Writeback</li>
* <li>AnonPages</li>
* <li>Mapped</li>
* <li>Shmem</li>
* <li>Slab</li>
* <li>SReclaimable</li>
* <li>SUnreclaim</li>
* <li>KernelStack</li>
* <li>PageTables</li>
* <li>NFS_Unstable</li>
* <li>Bounce</li>
* <li>WritebackTmp</li>
* <li>CommitLimit</li>
* <li>Committed_AS</li>
* <li>VmallocTotal</li>
* <li>VmallocUsed</li>
* <li>VmallocChunk</li>
* <li>HardwareCorrupted</li>
* <li>AnonHugePages</li>
* <li>Hugepagesize</li>
* <li>DirectMap4k</li>
* <li>DirectMap2M</li>
* </ul>
* @static
*/
public static function getMemInfo()
{
$result = [];
if ($n = preg_match_all('/^([\S]+):\s+(\d+)\skB$/im', file_get_contents('/proc/meminfo'), $matches)) {
for ($i = 0; $i < $n; $i++) {
$result[$matches[1][$i]] = $matches[2][$i];
}
}
return $result;
}
/**
* Get disk usage on UNIX OS
*
* @return array Partitions space usage. Every partition (array element) consist of:
* <ul>
* <li>0 - Device</li>
* <li>1 - Capacity in kB</li>
* <li>2 - Used kB</li>
* <li>3 - Available Kb</li>
* <li>4 - Use percentage</li>
* <li>5 - Mount point</li>
* </ul>
* @static
*/
public static function getDiskUsage()
{
$result = [];
$lines = explode("\n", trim(shell_exec('df')));
array_shift($lines);
foreach ($lines as &$line) {
if (0 === strpos($line, '/')) {
$result[] = explode("\t", $line);
}
}
return $result;
}
/**
* Get unique system ID
*
* @return string System ID
* @static
*/
public static function getHostId()
{
if (self::isWindows()) {
$uuid = explode("\r\n", trim(shell_exec('wmic csproduct get UUID')));
return (\count($uuid) === 2 ? $uuid[1] : false);
}
$uuid = trim(shell_exec('hostid'));
return $uuid === null ? false : $uuid;
}
/**
* Get server hostname
*
* @return string Server hostname
* @static
*/
public static function getHostname()
{
return php_uname('n');
}
public static function isWindows()
{
return (0 === stripos(PHP_OS, 'WIN'));
}
/**
* Identify the version of php
*
* @return string
*/
public static function checkPhpVersion()
{
$version = null;
if (\defined('PHP_VERSION')) {
$version = PHP_VERSION;
} else {
$version = phpversion('');
}
//Case management system of ubuntu, php version return 5.2.4-2ubuntu5.2
if (strpos($version, '-') !== false) {
$version = substr($version, 0, strpos($version, '-'));
}
return $version;
}
/**
* Get the server variable SERVER_NAME
*
* @return string server name
*/
public static function getServerName()
{
if (array_key_exists('HTTP_X_FORWARDED_SERVER', $_SERVER) && $_SERVER['HTTP_X_FORWARDED_SERVER']) {
return $_SERVER['HTTP_X_FORWARDED_SERVER'];
}
return $_SERVER['SERVER_NAME'];
}
/**
* getMemoryLimit allow to get the memory limit in octet
*
* @return int the memory limit value in octet
*/
public static function getMemoryLimit()
{
$memory_limit = @ini_get('memory_limit');
return Tools::getOctets($memory_limit);
}
/**
* @return bool true if the server use 64bit arch
*/
public static function is64bit()
{
return (PHP_INT_MAX === '9223372036854775807');
}
/**
* @return bool true if php-cli is used
*/
public static function isPhpCli()
{
return (\defined('STDIN') ||
(strtolower(PHP_SAPI) === 'cli' && (!array_key_exists('REMOTE_ADDR', $_SERVER) || empty($_SERVER['REMOTE_ADDR']))));
}
/**
* Get max file upload size considering server settings and optional max value
*
* @param int $max_size optional max file size
*
* @return int max file size in bytes
*/
public static function getMaxUploadSize($max_size = 0)
{
$post_max_size = Tools::unformatBytes(ini_get('post_max_size'));
$upload_max_filesize = Tools::unformatBytes(ini_get('upload_max_filesize'));
if ($max_size > 0) {
$result = min($post_max_size, $upload_max_filesize, $max_size);
} else {
$result = min($post_max_size, $upload_max_filesize);
}
return $result;
}
}