如何解释 php_uname 的输出
Posted
技术标签:
【中文标题】如何解释 php_uname 的输出【英文标题】:How do I interpret the output of php_uname 【发布时间】:2014-02-03 11:14:27 【问题描述】:从manual我得到了信息:
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.
所以我创建了一个函数
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;
有没有办法从我在 Ubuntu 上的 uname 获得更多有用的信息?
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
尤其是从我机器上的“uname_version_info”部分找出发行版(漂亮的“Ubuntu 13.10”):
#23-Ubuntu SMP Mon Dec 9 18:17:04 UTC 2013
【问题讨论】:
至少在版本方面,r
标志没有给你你想要的吗?
没有。那是内核版本
【参考方案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);
将打印例如:
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】:不,没有。 uname
函数仅报告有关正在运行的内核的信息——它不包含有关正在使用的 Linux 发行版的任何信息。内核版本可能有时会偶然包含发行版的名称,但并非总是如此。
根据所使用的 Linux 发行版,信息可能在 /etc
的各种文件中提供,包括但不限于:
/etc/os-release
/etc/debian_version
/etc/lsb-release
/etc/redhat-release
【讨论】:
所以如果我不能从 PHP 读取这些文件,对于 ubuntu 我需要一个匹配表,显示每个内核版本的最新分布以上是关于如何解释 php_uname 的输出的主要内容,如果未能解决你的问题,请参考以下文章
scikit-learn RandomForestClassifier - 如何解释树输出?