Source for file Guess.php
Documentation is available at Guess.php
* @author Stig Bakken <ssb@php.net>
* @author Gregory Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version CVS: $Id: Guess.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since PEAR 0.1
// php_uname() without args returns the same as 'uname -a', or a PHP-custom
// PHP versions prior to 4.3 return the uname of the host where PHP was built,
// as of 4.3 it returns the uname of the host running the PHP code.
// Linux host.example.com 2.4.2-2 #1 Sun Apr 8 20:41:30 EDT 2001 i686 unknown
// Linux host 2.4.17 #2 SMP Tue Feb 12 15:10:04 CET 2002 i686 unknown
// FreeBSD host.example.com 3.3-STABLE FreeBSD 3.3-STABLE #0: Mon Feb 21 00:42:31 CET 2000 root@example.com:/usr/src/sys/compile/CONFIG i386
// FreeBSD host.example.com 4.3-RELEASE FreeBSD 4.3-RELEASE #1: Mon Jun 25 11:19:43 EDT 2001 root@example.com:/usr/src/sys/compile/CONFIG i386
// FreeBSD host.example.com 4.5-STABLE FreeBSD 4.5-STABLE #0: Wed Feb 6 23:59:23 CET 2002 root@example.com:/usr/src/sys/compile/CONFIG i386
// PC FreeBSD 4.5 w/uname from GNU shellutils:
// FreeBSD host.example.com 4.5-STABLE FreeBSD 4.5-STABLE #0: Wed Feb i386 unknown
// HP-UX iq B.10.10 A 9000/712 2008429113 two-user license
// HP 9000/712 HP-UX 10 w/uname from GNU shellutils:
// HP-UX host B.10.10 A 9000/712 unknown
// IBM RS6000/550 AIX 4.3:
// AIX host 3 4 000003531C00
// AIX 4.3 w/uname from GNU shellutils:
// AIX host 3 4 000003531C00 unknown
// SGI Onyx IRIX 6.5 w/uname from GNU shellutils:
// IRIX64 host 6.5 01091820 IP19 mips
// IRIX64 host 6.5 01091820 IP19
// SparcStation 20 Solaris 8 w/uname from GNU shellutils:
// SunOS host.example.com 5.8 Generic_108528-12 sun4m sparc
// SparcStation 20 Solaris 8:
// SunOS host.example.com 5.8 Generic_108528-12 sun4m sparc SUNW,SPARCstation-20
// Darwin home-eden.local 7.5.0 Darwin Kernel Version 7.5.0: Thu Aug 5 19:26:16 PDT 2004; root:xnu/xnu-517.7.21.obj~3/RELEASE_PPC Power Macintosh
// Mac OS X early versions
* - define endianness, to allow matchSignature("bigend") etc.
* Retrieves information about the current operating system
* This class uses php_uname() to grok information about the current OS
* @author Stig Bakken <ssb@php.net>
* @author Gregory Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
$parts = preg_split ('/\s+/', trim ($uname));
$release = $machine = $cpu = '';
$release = " $parts[3].$parts[2]";
$extra = $this->_detectGlibcVersion ();
// use only the first two digits from the kernel version
$release = preg_replace('/^([0-9]+\.[0-9]+).*/', '\1', $parts[2 ]);
if ($cpu == 'Macintosh') {
if ($parts[$n - 2 ] == 'Power') {
if ($cpu == 'Macintosh') {
if ($parts[$n - 2 ] == 'Power') {
$release = preg_replace('/^([0-9]+\.[0-9]+).*/', '\1', $parts[2 ]);
if (isset ($sysmap[$sysname])) {
$sysname = $sysmap[$sysname];
if (isset ($cpumap[$cpu])) {
return array ($sysname, $release, $cpu, $extra, $nodename);
function _detectGlibcVersion ()
return $glibc; // no need to run this multiple times
include_once "System.php";
// Use glibc's <features.h> header file to
// get major and minor version number:
if (@file_exists ('/usr/include/features.h') &&
@is_readable ('/usr/include/features.h')) {
if (!@file_exists ('/usr/bin/cpp') || !@is_executable ('/usr/bin/cpp')) {
$features_file = fopen ('/usr/include/features.h', 'rb');
while (!feof ($features_file)) {
$line = fgets ($features_file, 8192 );
if (!$line || (strpos ($line, '#define') === false )) {
if (strpos($line, '__GLIBC__')) {
// major version number #define __GLIBC__ version
$glibc_major = trim($line[2 ]);
if (isset ($glibc_minor)) {
if (strpos($line, '__GLIBC_MINOR__')) {
// got the minor version number
// #define __GLIBC_MINOR__ version
$glibc_minor = trim($line[2 ]);
if (isset ($glibc_major)) {
if (!isset ($glibc_major) || !isset ($glibc_minor)) {
return $glibc = 'glibc' . trim($glibc_major) . "." . trim($glibc_minor) ;
$fp = fopen($tmpfile, "w");
fwrite($fp, "#include <features.h>\n__GLIBC__ __GLIBC_MINOR__\n");
$cpp = popen(" /usr/bin/cpp $tmpfile" , "r");
while ($line = fgets($cpp, 1024 )) {
if ($line{0 } == '#' || trim($line) == '') {
if (list ($major, $minor) = explode(' ', trim($line))) {
if (!($major && $minor) && @is_link('/lib/libc.so.6')) {
// Let's try reading the libc.so.6 symlink
list ($major, $minor) = explode('.', $matches[1 ]);
if (!($major && $minor)) {
return $glibc = " glibc{$major}.{$minor}";
if (empty ($this->extra)) {
return "{ $this->sysname }-{$this->release }-{$this->cpu }";
return "{ $this->sysname }-{$this->release }-{$this->cpu }-{$this->extra }";
$matches += $this->_matchFragment ($fragments[0 ], $this->sysname);
$matches += $this->_matchFragment ($fragments[1 ], $this->release);
$matches += $this->_matchFragment ($fragments[2 ], $this->cpu);
$matches += $this->_matchFragment ($fragments[3 ], $this->extra);
function _matchFragment ($fragment, $value)
$reg = '/^' . str_replace(array ('*', '?', '/'), array ('.*', '.', '\\/'), $fragment) . '\\z/';
return ($fragment == '*' || !strcasecmp($fragment, $value));
Documentation generated on Wed, 06 Jul 2011 23:30:50 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.
|