├── .github └── FUNDING.yml ├── CHANGE.md ├── .gitignore ├── composer.json ├── SystemInfo.php ├── LICENSE ├── CONTRIBUTING.md ├── interfaces └── InfoInterface.php ├── README.md └── os ├── Linux.php └── Windows.php /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [abhi1693] 4 | custom: ['https://paypal.me/AbhimanyuSaharan'] 5 | -------------------------------------------------------------------------------- /CHANGE.md: -------------------------------------------------------------------------------- 1 | v1.0.1 [Work in progress] 2 | ------------------------- 3 | 4 | - Changed composer install path to yii2-system-info 5 | - Added more Methods 6 | - Small bug fixes 7 | 8 | v1.0.0 [2014-02-16] 9 | ------------------- 10 | 11 | - Initial Release 12 | - Added new Methods -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # idea 2 | .idea 3 | 4 | composer.phar 5 | composer.lock 6 | vendor/ 7 | 8 | # Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file 9 | # You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file 10 | # composer.lock 11 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "abhi1693/yii2-system-info", 3 | "description": "Information about the server", 4 | "license": "MIT", 5 | "authors": [ 6 | { 7 | "name": "Abhimanyu Saharan", 8 | "email": "desk.abhimanyu@gmail.com", 9 | "homepage": "http://abhi1693.github.io/yii2-system-info" 10 | } 11 | ], 12 | "require": { 13 | "php": ">=5.4.0", 14 | "yiisoft/yii2": "*" 15 | }, 16 | "autoload": { 17 | "psr-4": {"abhimanyu\\systemInfo\\": ""} 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /SystemInfo.php: -------------------------------------------------------------------------------- 1 | db->driverName; 255 | } 256 | 257 | /** 258 | * * Gets the current DB Version of Yii2 259 | * 260 | * @return mixed 261 | */ 262 | public static function getDbVersion() 263 | { 264 | return Yii::$app->db->pdo->getAttribute(PDO::ATTR_SERVER_VERSION); 265 | } 266 | 267 | private static function getMemoryInfo() 268 | { 269 | $data = @explode("\n", file_get_contents("/proc/meminfo")); 270 | 271 | } 272 | } -------------------------------------------------------------------------------- /os/Windows.php: -------------------------------------------------------------------------------- 1 | ExecQuery("SELECT Caption FROM Win32_OperatingSystem") as $os) { 28 | return $os->Caption; 29 | } 30 | 31 | return "Windows"; 32 | } 33 | 34 | public static function getInstance() 35 | { 36 | $wmi = new \COM('winmgmts:{impersonationLevel=impersonate}//./root/cimv2'); 37 | 38 | if (!is_object($wmi)) { 39 | throw new Exception('This needs access to WMI. Please enable DCOM in php.ini and allow the current 40 | user to access the WMI DCOM object.'); 41 | } 42 | 43 | return $wmi; 44 | } 45 | 46 | /** 47 | * Gets the Kernel Version of the Operating System 48 | * 49 | * @return string 50 | */ 51 | public static function getKernelVersion() 52 | { 53 | $wmi = Windows::getInstance(); 54 | 55 | foreach ($wmi->ExecQuery("SELECT WindowsVersion FROM Win32_Process WHERE Handle = 0") as $process) { 56 | return $process->WindowsVersion; 57 | } 58 | 59 | return "Unknown"; 60 | } 61 | 62 | 63 | /** 64 | * Gets the hostname 65 | * 66 | * @return string 67 | */ 68 | public static function getHostname() 69 | { 70 | $wmi = Windows::getInstance(); 71 | 72 | foreach ($wmi->ExecQuery("SELECT Name FROM Win32_ComputerSystem") as $cs) { 73 | return $cs->Name; 74 | } 75 | 76 | return "Unknown"; 77 | } 78 | 79 | /** 80 | * Gets Processor's Model 81 | * 82 | * @return string 83 | */ 84 | public static function getCpuModel() 85 | { 86 | $wmi = Windows::getInstance(); 87 | 88 | $object = $wmi->ExecQuery("SELECT Name FROM Win32_Processor"); 89 | 90 | foreach ($object as $cpu) { 91 | return $cpu->Name; 92 | } 93 | 94 | return 'Unknown'; 95 | } 96 | 97 | /** 98 | * Gets Processor's Vendor 99 | * 100 | * @return string 101 | */ 102 | public static function getCpuVendor() 103 | { 104 | $wmi = Windows::getInstance(); 105 | 106 | $object = $wmi->ExecQuery("SELECT Manufacturer FROM Win32_Processor"); 107 | 108 | foreach ($object as $cpu) { 109 | return $cpu->Manufacturer; 110 | } 111 | 112 | return 'Unknown'; 113 | } 114 | 115 | /** 116 | * Gets Processor's Frequency 117 | * 118 | * @return string 119 | */ 120 | public static function getCpuFreq() 121 | { 122 | $wmi = Windows::getInstance(); 123 | 124 | $object = $wmi->ExecQuery("SELECT CurrentClockSpeed FROM Win32_Processor"); 125 | 126 | foreach ($object as $cpu) { 127 | return $cpu->CurrentClockSpeed; 128 | } 129 | 130 | return 'Unknown'; 131 | } 132 | 133 | /** 134 | * Gets current system load 135 | * 136 | * @return string 137 | */ 138 | public static function getLoad() 139 | { 140 | $wmi = Windows::getInstance(); 141 | $load = []; 142 | 143 | foreach ($wmi->ExecQuery("SELECT LoadPercentage FROM Win32_Processor") as $cpu) { 144 | $load[] = $cpu->LoadPercentage; 145 | } 146 | 147 | return round(array_sum($load) / count($load), 2) . "%"; 148 | } 149 | 150 | /** 151 | * Gets Processor's Architecture 152 | * 153 | * @return string 154 | */ 155 | public static function getCpuArchitecture() 156 | { 157 | $wmi = Windows::getInstance(); 158 | 159 | foreach ($wmi->ExecQuery("SELECT Architecture FROM Win32_Processor") as $cpu) { 160 | switch ($cpu->Architecture) { 161 | case 0: 162 | return "x86"; 163 | case 1: 164 | return "MIPS"; 165 | case 2: 166 | return "Alpha"; 167 | case 3: 168 | return "PowerPC"; 169 | case 6: 170 | return "Itanium-based systems"; 171 | case 9: 172 | return "x64"; 173 | } 174 | } 175 | 176 | return "Unknown"; 177 | } 178 | 179 | /** 180 | * Gets system up-time 181 | * 182 | * @return string 183 | */ 184 | public static function getUpTime() 185 | { 186 | $wmi = Windows::getInstance(); 187 | 188 | $booted_str = ''; 189 | foreach ($wmi->ExecQuery("SELECT LastBootUpTime FROM Win32_OperatingSystem") as $os) { 190 | $booted_str = $os->LastBootUpTime; 191 | } 192 | 193 | $booted = [ 194 | 'year' => substr($booted_str, 0, 4), 195 | 'month' => substr($booted_str, 4, 2), 196 | 'day' => substr($booted_str, 6, 2), 197 | 'hour' => substr($booted_str, 8, 2), 198 | 'minute' => substr($booted_str, 10, 2), 199 | 'second' => substr($booted_str, 12, 2) 200 | ]; 201 | $booted_ts = mktime($booted['hour'], $booted['minute'], $booted['second'], $booted['month'], $booted['day'], $booted['year']); 202 | 203 | return date('m/d/y h:i A (T)', $booted_ts); 204 | } 205 | 206 | /** 207 | * Gets total number of cores 208 | * 209 | * @return integer 210 | */ 211 | public static function getCpuCores() 212 | { 213 | $wmi = Windows::getInstance(); 214 | $object = $wmi->ExecQuery("SELECT NumberOfLogicalProcessors FROM Win32_Processor"); 215 | 216 | $cores = 0; 217 | foreach ($object as $obj) { 218 | $cores = $obj->NumberOfLogicalProcessors; 219 | } 220 | 221 | return $cores; 222 | } 223 | 224 | /** 225 | * Gets Current PHP Version 226 | * 227 | * @return string 228 | */ 229 | public static function getPhpVersion() 230 | { 231 | return phpversion(); 232 | } 233 | 234 | /** 235 | * Gets Server Name 236 | * 237 | * @return string 238 | */ 239 | public static function getServerName() 240 | { 241 | return $_SERVER['SERVER_NAME']; 242 | } 243 | 244 | /** 245 | * Gets Server Protocol 246 | * 247 | * @return string 248 | */ 249 | public static function getServerProtocol() 250 | { 251 | return $_SERVER['SERVER_PROTOCOL']; 252 | } 253 | 254 | /** 255 | * Gets the type of server e.g. apache 256 | * 257 | * @return string 258 | */ 259 | public static function getServerSoftware() 260 | { 261 | return $_SERVER['SERVER_SOFTWARE']; 262 | } 263 | 264 | /** 265 | * Gets total physical memory 266 | * 267 | * @return array|null 268 | */ 269 | public static function getTotalMemory() 270 | { 271 | $wmi = Windows::getInstance(); 272 | 273 | foreach ($wmi->ExecQuery("SELECT TotalPhysicalMemory FROM Win32_ComputerSystem") as $mem) { 274 | return $mem->TotalPhysicalMemory; 275 | } 276 | 277 | return NULL; 278 | } 279 | 280 | /** 281 | * Gets the current DB Type of Yii2 282 | * 283 | * @return mixed 284 | */ 285 | public static function getDbType() 286 | { 287 | return Yii::$app->db->driverName; 288 | } 289 | 290 | /** 291 | * * Gets the current DB Version of Yii2 292 | * 293 | * @return mixed 294 | */ 295 | public static function getDbVersion() 296 | { 297 | try { 298 | // Open Connection if closed 299 | Yii::$app->db->open(); 300 | } catch (Exception $e) { 301 | //ignore 302 | } 303 | 304 | return Yii::$app->db->pdo->getAttribute(PDO::ATTR_SERVER_VERSION); 305 | } 306 | } --------------------------------------------------------------------------------