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