* $info = ezcSystemInfo::getInstance(); * echo 'Processors: ', $info->cpuCount, "\n"; * echo 'CPU Type: ', $info->cpuType, "\n"; * echo 'CPU Speed: ', $info->cpuSpeed, "\n"; * * * @package SystemInformation * @version //autogentag// * @mainclass */ class ezcSystemInfo { /** * Instance of the singleton ezcSystemInfo object. * * Use the getInstance() method to retrieve the instance. * * @var ezcSystemInfo */ private static $instance = null; /** * Contains object that provide info about the underlying OS. * * @var ezcSystemInfoReader */ private $systemInfoReader = null; /** * Contains string with the type of the underlying OS * or empty string if OS can't be detected. * * @var string */ private $osType = null; /** * Contains string with the name of the underlying OS * or empty string if OS can't be detected. * * @var string */ private $osName = null; /** * Contains string with the filesystem type of the underlying OS * or empty string if OS can't be detected. * * @var string */ private $fileSystemType = null; /** * Contains string with the line separator of the underlying OS * or empty string if OS can't be detected. * * @var string */ private $lineSeparator = null; /** * Contains string with the backup file name of the underlying OS * or empty string if OS can't be detected. * * @var string */ private $backupFileName = null; /** * Returns the single instance of the ezcSystemInfo class. * * @throws ezcSystemInfoReaderCantScanOSException * If system variables can't be received from OS. * @return ezcSystemInfo */ public static function getInstance() { if ( is_null( self::$instance ) ) { self::$instance = new self(); } return self::$instance; } /** * Constructs ezcSystemInfo object, inits it with corresponding underlying OS data. * * @throws ezcSystemInfoReaderCantScanOSException * If system variables can't be received from OS. */ private function __construct() { $this->init(); } /** * Detects underlying system and sets system properties. * * @throws ezcSystemInfoReaderCantScanOSException * If system variables can't be received from OS. */ private function init() { $this->setSystemInfoReader(); } /** * Sets the systemInfoReader depending on the OS and fills in the system * information internally. * * Returns true if it was able to set appropriate systemInfoReader * or false if failed. * * @throws ezcSystemInfoReaderCantScanOSException * If system variables can't be received from OS. * @return bool */ private function setSystemInfoReader() { // Determine OS $uname = php_uname( 's' ); if ( substr( $uname, 0, 7 ) == 'Windows' ) { $this->systemInfoReader = new ezcSystemInfoWindowsReader( $uname ); $this->osType = 'win32'; $this->osName = 'Windows'; $this->fileSystemType = 'win32'; $this->lineSeparator= "\r\n"; $this->backupFileName = '.bak'; } else if ( substr( $uname, 0, 6 ) == 'Darwin' ) { $this->systemInfoReader = new ezcSystemInfoMacReader(); $this->osType = 'mac'; $this->osName = 'Mac OS X'; $this->fileSystemType = 'unix'; $this->lineSeparator= "\n"; $this->backupFileName = '~'; } else { $this->osType = 'unix'; if ( strtolower( $uname ) == 'linux' ) { $this->systemInfoReader = new ezcSystemInfoLinuxReader(); $this->osName = 'Linux'; $this->fileSystemType = 'unix'; $this->lineSeparator= "\n"; $this->backupFileName = '~'; } else if ( strtolower( substr( $uname, 0, 7 ) ) == 'freebsd' ) { $this->systemInfoReader = new ezcSystemInfoFreeBsdReader(); $this->osName = 'FreeBSD'; $this->fileSystemType = 'unix'; $this->lineSeparator= "\n"; $this->backupFileName = '~'; } else { $this->systemInfoReader = null; return false; } } return true; } /** * Detects if a PHP accelerator is running and what type it is. * * @return ezcSystemInfoAccelerator or null if no PHP accelerator detected */ public static function phpAccelerator() { $phpAcceleratorInfo = null; if ( ezcBaseFeatures::hasExtensionSupport( "Turck MMCache" ) ) { $phpAcceleratorInfo = new ezcSystemInfoAccelerator( "Turck MMCache", // name "http://turck-mmcache.sourceforge.net", // url true, // isEnabled false, // version int false // version string ); } if ( ezcBaseFeatures::hasExtensionSupport( "eAccelerator" ) ) { $phpAcceleratorInfo = new ezcSystemInfoAccelerator( "eAccelerator", // name "http://sourceforge.net/projects/eaccelerator/", // url true, // isEnabled false, // version int phpversion( 'eAccelerator' ) // version string ); } if ( ezcBaseFeatures::hasExtensionSupport( "apc" ) ) { $phpAcceleratorInfo = new ezcSystemInfoAccelerator( "APC", // name "http://pecl.php.net/package/APC", // url ( ini_get( 'apc.enabled' ) != 0 ), // isEnabled false, // version int phpversion( 'apc' ) // version string ); } if ( ezcBaseFeatures::hasExtensionSupport( "Zend Performance Suite" ) ) { $phpAcceleratorInfo = new ezcSystemInfoAccelerator( "Zend Performance Suite", // name "http://www.zend.com/en/products/platform/", // url true, // isEnabled false, // version int false // version string ); } if ( ezcBaseFeatures::hasExtensionSupport( 'XCache' ) ) { $phpAcceleratorInfo = new ezcSystemInfoAccelerator( "XCache", // name "http://xcache.lighttpd.net/", // url true, // isEnabled false, // version int phpversion( 'XCache' ) // version string ); } return $phpAcceleratorInfo; } /** * Determines if the script was executed over the web or the shell/command line. * * @return bool */ public static function isShellExecution() { $sapiType = php_sapi_name(); if ( $sapiType == 'cli' ) { return true; } // For CGI we have to check, if the script has been executed over shell. // Currently it looks like the HTTP_HOST variable is the most reasonable to check. if ( substr( $sapiType, 0, 3 ) == 'cgi' ) { if ( !isset( $_SERVER['HTTP_HOST'] ) ) { return true; } else { return false; } } return false; } /** * Returns the PHP version as an array with the version elements. * * @return array(string) */ public static function phpVersion() { return explode( '.', phpVersion() ); } /** * Property read access. * * @throws ezcBasePropertyNotFoundException * If the the desired property is not found. * @param string $property Name of the property. * @return mixed Value of the property or null. * @ignore */ public function __get( $property ) { if ( $this->systemInfoReader == null && ( $property == 'cpuType' || $property == 'cpuCount' || $property == 'cpuSpeed' || $property == 'memorySize' ) ) { return null; } switch ( $property ) { case 'osType': return $this->osType; case 'osName': return $this->osName; case 'fileSystemType': return $this->fileSystemType; case 'cpuCount': return $this->systemInfoReader->getCpuCount(); case 'cpuType': return $this->systemInfoReader->cpuType(); case 'cpuSpeed': return $this->systemInfoReader->cpuSpeed(); case 'memorySize': return $this->systemInfoReader->memorySize(); case 'lineSeparator': return $this->lineSeparator; case 'backupFileName': return $this->backupFileName; case 'phpVersion': return $this->phpVersion(); case 'phpAccelerator': return $this->phpAccelerator(); case 'isShellExecution': return $this->isShellExecution(); default: break; } throw new ezcBasePropertyNotFoundException( $property ); } } ?>