1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the O2System Framework package. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
* |
8
|
|
|
* @author Steeve Andrian Salim |
9
|
|
|
* @copyright Copyright (c) Steeve Andrian Salim |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
// ------------------------------------------------------------------------ |
13
|
|
|
|
14
|
|
|
namespace O2System\Filesystem; |
15
|
|
|
|
16
|
|
|
// ------------------------------------------------------------------------ |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class System |
20
|
|
|
* |
21
|
|
|
* @package O2System\Filesystem |
22
|
|
|
*/ |
23
|
|
|
class System |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* System::getInfo |
27
|
|
|
* |
28
|
|
|
* Gets system info. |
29
|
|
|
* |
30
|
|
|
* @link http://php.net/manual/en/function.php-uname.php |
31
|
|
|
* |
32
|
|
|
* @return string Returns the description, as a string. |
33
|
|
|
*/ |
34
|
|
|
public function getInfo() |
35
|
|
|
{ |
36
|
|
|
return php_uname(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
// ------------------------------------------------------------------------ |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* System::getHostname |
43
|
|
|
* |
44
|
|
|
* Gets system hostname. |
45
|
|
|
* |
46
|
|
|
* @return string Host name. eg. localhost.example.com. |
47
|
|
|
*/ |
48
|
|
|
public function getHostname() |
49
|
|
|
{ |
50
|
|
|
return php_uname('n'); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
// ------------------------------------------------------------------------ |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* System::getName |
57
|
|
|
* |
58
|
|
|
* Gets operating system name. |
59
|
|
|
* |
60
|
|
|
* @return string Operating system name. eg. FreeBSD. |
61
|
|
|
*/ |
62
|
|
|
public function getName() |
63
|
|
|
{ |
64
|
|
|
return php_uname('s'); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
// ------------------------------------------------------------------------ |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* System::getVersion |
71
|
|
|
* |
72
|
|
|
* Gets version of operating system. |
73
|
|
|
* |
74
|
|
|
* @return string Version information. Varies a lot between operating systems. |
75
|
|
|
*/ |
76
|
|
|
public function getVersion() |
77
|
|
|
{ |
78
|
|
|
return php_uname('v'); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
// ------------------------------------------------------------------------ |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* System::getRelease |
85
|
|
|
* |
86
|
|
|
* Gets release name of operating system |
87
|
|
|
* |
88
|
|
|
* @return string Release name. eg. 5.1.2-RELEASE. |
89
|
|
|
*/ |
90
|
|
|
public function getRelease() |
91
|
|
|
{ |
92
|
|
|
return php_uname('r'); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
// ------------------------------------------------------------------------ |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* System::getMachine |
99
|
|
|
* |
100
|
|
|
* Gets machine type. |
101
|
|
|
* |
102
|
|
|
* @return string Machine type. eg. i386. |
103
|
|
|
*/ |
104
|
|
|
public function getMachine() |
105
|
|
|
{ |
106
|
|
|
return php_uname('m'); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
// ------------------------------------------------------------------------ |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* System::getPhpSapi |
113
|
|
|
* |
114
|
|
|
* Returns a lowercase string that describes the type of interface (the Server API, SAPI) that PHP is using. For |
115
|
|
|
* example, in CLI PHP this string will be "cli" whereas with Apache it may have several different values depending |
116
|
|
|
* on the exact SAPI used. Possible values are listed below. |
117
|
|
|
* |
118
|
|
|
* @link http://php.net/manual/en/function.php-sapi-name.php |
119
|
|
|
* |
120
|
|
|
* @return string Returns the interface type, as a lowercase string. |
121
|
|
|
*/ |
122
|
|
|
public function getPhpSapi() |
123
|
|
|
{ |
124
|
|
|
return php_sapi_name(); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
// ------------------------------------------------------------------------ |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* System::getPhpVersion |
131
|
|
|
* |
132
|
|
|
* Gets the current PHP version |
133
|
|
|
* |
134
|
|
|
* @return void If the optional extension parameter is specified, phpversion() returns the version of that |
135
|
|
|
* extension, or FALSE if there is no version information associated or the extension isn't enabled. |
136
|
|
|
*/ |
137
|
|
|
public function getPhpVersion() |
138
|
|
|
{ |
139
|
|
|
return phpversion(); |
|
|
|
|
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
// ------------------------------------------------------------------------ |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* System::getPhpExtensionVersion |
146
|
|
|
* |
147
|
|
|
* Gets php extension version. |
148
|
|
|
* |
149
|
|
|
* @param string $extension An optional extension name. |
150
|
|
|
* |
151
|
|
|
* @return void |
152
|
|
|
*/ |
153
|
|
|
public function getPhpExtensionVersion($extension) |
154
|
|
|
{ |
155
|
|
|
return phpversion($extension); |
|
|
|
|
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
// ------------------------------------------------------------------------ |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* System::getPhpExtensions |
162
|
|
|
* |
163
|
|
|
* Gets Php Extensions |
164
|
|
|
* |
165
|
|
|
* @param boolean $zendExtensions |
166
|
|
|
* |
167
|
|
|
* @return array Returns an array with the names of all modules compiled and loaded |
168
|
|
|
*/ |
169
|
|
|
public function getPhpExtensions($zendExtensions = false) |
170
|
|
|
{ |
171
|
|
|
return get_loaded_extensions($zendExtensions); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
// ------------------------------------------------------------------------ |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* System::isPhpExtensionLoaded |
178
|
|
|
* |
179
|
|
|
* Get Status Is Php Extension Loaded. |
180
|
|
|
* |
181
|
|
|
* @param string $extension An optional extension name. |
182
|
|
|
* |
183
|
|
|
* @return boolean |
184
|
|
|
*/ |
185
|
|
|
public function isPhpExtensionLoaded($extension) |
186
|
|
|
{ |
187
|
|
|
return (bool)extension_loaded($extension); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
// ------------------------------------------------------------------------ |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* System::getZendVersion |
194
|
|
|
* |
195
|
|
|
* Gets the version of the current Zend engine |
196
|
|
|
* |
197
|
|
|
* @return string Returns the Zend Engine version number, as a string. |
198
|
|
|
*/ |
199
|
|
|
public function getZendVersion() |
200
|
|
|
{ |
201
|
|
|
return zend_version(); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
// ------------------------------------------------------------------------ |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* System::getZendOptimizerVersion |
208
|
|
|
* |
209
|
|
|
* Gets Version of Zend Optimizer |
210
|
|
|
* |
211
|
|
|
* @return boolean Returns TRUE if function_name exists and is a function, FALSE otherwise. |
212
|
|
|
*/ |
213
|
|
|
public function getZendOptimizerVersion() |
214
|
|
|
{ |
215
|
|
|
return function_exists('zend_optimizer_version') ? zend_optimizer_version() : false; |
|
|
|
|
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
// ------------------------------------------------------------------------ |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* System::getConfigurations |
222
|
|
|
* |
223
|
|
|
* @param null|string $extension An Optional extension name |
224
|
|
|
* @param boolean $details |
225
|
|
|
* |
226
|
|
|
* @return mixed Returns the return value of the callback, or FALSE on error. |
227
|
|
|
*/ |
228
|
|
|
public function getConfigurations($extension = null, $details = true) |
229
|
|
|
{ |
230
|
|
|
return call_user_func_array('ini_get_all', func_get_args()); |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
// ------------------------------------------------------------------------ |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* System::getMacAddress |
237
|
|
|
* |
238
|
|
|
* Gets system mac address. |
239
|
|
|
* |
240
|
|
|
* @return string |
241
|
|
|
*/ |
242
|
|
|
public function getMacAddress() |
243
|
|
|
{ |
244
|
|
|
switch (PHP_OS) { |
245
|
|
|
default: |
246
|
|
|
case 'Darwin': |
247
|
|
|
case 'FreeBSD': |
248
|
|
|
$cmd = '/sbin/ifconfig'; |
249
|
|
|
break; |
250
|
|
|
case 'Windows': |
251
|
|
|
$cmd = "ipconfig /all "; |
252
|
|
|
break; |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
$string = trim(shell_exec($cmd)); |
256
|
|
|
|
257
|
|
|
if (preg_match_all('/([0-9a-f]{2}:){5}\w\w/i', $string, $matches)) { |
258
|
|
|
if (isset($matches[ 0 ])) { |
259
|
|
|
return reset($matches[ 0 ]); // get first mac address |
260
|
|
|
} |
261
|
|
|
} else { |
262
|
|
|
return implode(':', str_split(substr(md5('none'), 0, 12), 2)); |
263
|
|
|
} |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
// ------------------------------------------------------------------------ |
267
|
|
|
|
268
|
|
|
/** |
269
|
|
|
* System::getLoadAvg |
270
|
|
|
* |
271
|
|
|
* Gets system load averages. |
272
|
|
|
* |
273
|
|
|
* @param int $interval |
274
|
|
|
* |
275
|
|
|
* @return float |
276
|
|
|
*/ |
277
|
|
|
public function getLoadAvg($interval = 1) |
278
|
|
|
{ |
279
|
|
|
$rs = sys_getloadavg(); |
280
|
|
|
$interval = $interval >= 1 && 3 <= $interval ? $interval : 1; |
281
|
|
|
$load = $rs[ $interval ]; |
282
|
|
|
|
283
|
|
|
return round(($load * 100) / $this->getCpuCores(), 2); |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
// ------------------------------------------------------------------------ |
287
|
|
|
|
288
|
|
|
/** |
289
|
|
|
* System::getCpuCores |
290
|
|
|
* |
291
|
|
|
* Gets the numbers of system cores. |
292
|
|
|
* |
293
|
|
|
* @return int |
294
|
|
|
*/ |
295
|
|
|
public function getCpuCores() |
296
|
|
|
{ |
297
|
|
|
$numCpus = 1; |
298
|
|
|
if (is_file('/proc/cpuinfo')) { |
299
|
|
|
$cpuinfo = file_get_contents('/proc/cpuinfo'); |
300
|
|
|
preg_match_all('/^processor/m', $cpuinfo, $matches); |
301
|
|
|
$numCpus = count($matches[ 0 ]); |
302
|
|
|
} else { |
303
|
|
|
if ('WIN' == strtoupper(substr(PHP_OS, 0, 3))) { |
304
|
|
|
$process = @popen('wmic cpu get NumberOfCores', 'rb'); |
305
|
|
|
if (false !== $process) { |
306
|
|
|
fgets($process); |
307
|
|
|
$numCpus = intval(fgets($process)); |
308
|
|
|
pclose($process); |
309
|
|
|
} |
310
|
|
|
} else { |
311
|
|
|
$process = @popen('sysctl -a', 'rb'); |
312
|
|
|
if (false !== $process) { |
313
|
|
|
$output = stream_get_contents($process); |
314
|
|
|
preg_match('/hw.ncpu: (\d+)/', $output, $matches); |
315
|
|
|
if ($matches) { |
316
|
|
|
$numCpus = intval($matches[ 1 ][ 0 ]); |
317
|
|
|
} |
318
|
|
|
pclose($process); |
319
|
|
|
} |
320
|
|
|
} |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
return $numCpus; |
324
|
|
|
} |
325
|
|
|
} |