/** * Get system memory capacity on windows systems * * @return array * @throws Exception\RuntimeException */ protected static function getSystemMemoryCapacityWin() { if (function_exists('win32_ps_stat_mem')) { $memstat = win32_ps_stat_mem(); } elseif (!function_exists('exec')) { throw new Exception\RuntimeException("Missing php extension 'win32ps' and the build-in function 'exec' is disabled"); } else { // call [DIR]\_win\GlobalMemoryStatus.exe $cmd = escapeshellarg(__DIR__ . DIRECTORY_SEPARATOR . '_win' . DIRECTORY_SEPARATOR . 'GlobalMemoryStatus.exe'); $out = $ret = null; $line = exec($cmd, $out, $ret); if ($ret) { $out = implode("\n", $out); throw new Exception\RuntimeException("Command '{$cmd}' failed" . ", return: '{$ret}'" . ", output: '{$out}'"); } elseif (!($memstat = @unserialize($line))) { $err = error_get_last(); $out = implode("\n", $out); throw new Exception\RuntimeException("Can't parse output of command '{$cmd}'" . ": {$err['message']}" . ", output: '{$out}'"); } } if (!isset($memstat['total_phys'], $memstat['avail_phys'])) { throw new Exception\RuntimeException("Can't detect memory status"); } return array('total' => $memstat['total_phys'], 'free' => $memstat['avail_phys']); }
/** * Scans the OS and fills in the information internally. * Returns true if it was able to scan the system or false if it failed. * * @param string $dmesgPath path to the source of system information in OS * @return bool */ private function getOsInfo() { // query contents of CentralProcessor section. $output = shell_exec("reg query HKLM\\HARDWARE\\DESCRIPTION\\SYSTEM\\CentralProcessor"); $outputStrings = explode("\n", $output); // In first two items of output strings we have the signature of reg.exe utility // and path to CentralProcessor section than list of subsections paths follows. // One subsection represent info for one CPU. // Name of each subsection is index of CPU starting from 0. if (is_array($outputStrings) && count($outputStrings) > 2) { $this->cpuCount = count($outputStrings) - 2; // cpuCount is amount of subsections, output header skipped. for ($i = 0; $i < $this->cpuCount; $i++) { $output = shell_exec("reg query HKLM\\HARDWARE\\DESCRIPTION\\SYSTEM\\CentralProcessor\\{$i} /v ProcessorNameString"); preg_match("/ProcessorNameString\\s*\\S*\\s*(.*)/", $output, $matches); if (isset($matches[1])) { $this->cpuType[] = $matches[1]; $this->validProperties['cpuType'] = $this->cpuType; } unset($matches); $output = shell_exec("reg query HKLM\\HARDWARE\\DESCRIPTION\\SYSTEM\\CentralProcessor\\{$i} /v ~MHz"); preg_match("/~MHz\\s*\\S*\\s*(\\S*)/", $output, $matches); if (isset($matches[1])) { $this->cpuSpeed[] = (double) hexdec($matches[1]) . '.0'; // force to be float value $this->validProperties['cpu_count'] = $this->cpuCount; $this->validProperties['cpu_speed'] = $this->cpuSpeed; } unset($matches); } } // if no php_win32ps.dll extension installed than scanning of // Total Physical memory is not supported. // It's could be implemented on WinXP and Win2003 using call to // Windows Management Instrumentation (WMI) service like "wmic memphysical" // (should be researched in details) or with help of some free third party // utility like psinfo.exe from SysInternals ( www.sysinternals.com ). if (ezcBaseFeatures::hasExtensionSupport('win32ps')) { $memInfo = win32_ps_stat_mem(); $this->memorySize = $memInfo['total_phys'] * $memInfo['unit']; $this->validProperties['memory_size'] = $this->memorySize; } return true; }