How do I interpret the output of php_uname

2019-02-19 10:58发布

问题:

From the manual I got the information:

mode is a single character that defines what information is returned:

    'a': This is the default. Contains all modes in the sequence "s n r v m".
    's': Operating system name. eg. FreeBSD.
    'n': Host name. eg. localhost.example.com.
    'r': Release name. eg. 5.1.2-RELEASE.
    'v': Version information. Varies a lot between operating systems.
    'm': Machine type. eg. i386.

So I created a function

function interpret_php_uname(){
    $release_info["os_name"] = php_uname('s');
    $release_info["uname_version_info"] = php_uname('v');
    $release_info["machine_type"] = php_uname('m');
    $release_info["php_uname"] = php_uname();
    return $release_info;
}

is there a way to get more useful information from my uname on Ubuntu?

Linux geisterhaufen 3.11.0-15-generic #23-Ubuntu SMP Mon Dec 9 18:17:04 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

especially find out the distribution (saucy "Ubuntu 13.10") from the part "uname_version_info" which is this on my machine:

#23-Ubuntu SMP Mon Dec 9 18:17:04 UTC 2013

回答1:

<?php
function interpret_php_uname(){
    $release_info["os_name"] = php_uname('s');
    $release_info["uname_version_info"] = php_uname('v');
    $release_info["machine_type"] = php_uname('m');
    $release_info["kernel"] = php_uname('r');
    $release_info["php_uname"] = php_uname();

    $distribution["4.10"]=array("Warty Warthog", "2.6.8");
    $distribution["5.04"]=array("Hoary Hedgehog", "2.6.10");
    $distribution["5.10"]=array("Breezy Badger", "2.6.12");
    $distribution["6.06"]=array("Dapper Drake", "2.6.15");
    $distribution["6.10"]=array("Edgy Eft", "2.6.17");
    $distribution["7.04"]=array("Feisty Fawn", "2.6.20");
    $distribution["7.10"]=array("Gutsy Gibbon", "2.6.22");
    $distribution["8.04"]=array("Hardy Heron", "2.6.24");
    $distribution["8.10"]=array("Intrepid Ibex", "2.6.27");
    $distribution["9.04"]=array("Jaunty Jackalope", "2.6.28");
    $distribution["9.10"]=array("Karmic Koala", "2.6.31");
    $distribution["10.04"]=array("Lucid Lynx", "2.6.32");
    $distribution["10.10"]=array("Maverick Meerkat", "2.6.35");
    $distribution["11.04"]=array("Natty Narwhal", "2.6.38");
    $distribution["11.10"]=array("Oneiric Ocelot", "3.0");
    $distribution["12.04"]=array("Precise Pangolin", "3.2");
    $distribution["12.10"]=array("Quantal Quetzal", "3.5");
    $distribution["13.04"]=array("Raring Ringtail", "3.8");
    $distribution["13.10"]=array("Saucy Salamander", "3.11");
    $distribution["14.04"]=array("Trusty Tahr", "3.13");

    foreach($distribution as $distribution=>$name_kernel){
        list($name,$kernel)=$name_kernel;
        if(version_compare($release_info["kernel"],$kernel,'>=')) {
            $release_info["ubuntu_distribution"]=$distribution;
            $release_info["ubuntu_distribution_name"]=$name;
        }
    }

    return $release_info;
}
$release_info=interpret_php_uname();
var_export($release_info);

will print for example:

array (
  'os_name' => 'Linux',
  'uname_version_info' => '#23-Ubuntu SMP Mon Dec 9 18:17:04 UTC 2013',
  'machine_type' => 'x86_64',
  'kernel' => '3.11.0-15-generic',
  'php_uname' => 'Linux geisterhaufen 3.11.0-15-generic #23-Ubuntu SMP Mon Dec 9 18:17:04 UTC 2013 x86_64',
  'ubuntu_distribution' => '13.10',
  'ubuntu_distribution_name' => 'Saucy Salamander',
)


回答2:

No, there is not. The uname function only reports information about the running kernel — it does not contain any information about the Linux distribution being used. The kernel version may sometimes incidentally include the name of the distribution, but this is not always the case.

Depending on what Linux distribution is being used, information may be available in a variety of files in /etc, including but not limited to:

/etc/os-release
/etc/debian_version
/etc/lsb-release
/etc/redhat-release


标签: php ubuntu uname