从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
答案 0 :(得分: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',
)
答案 1 :(得分:0)
不,没有。 uname
函数仅报告有关正在运行的内核的信息 - 它不包含有关正在使用的Linux发行版的任何信息。内核版本可能有时偶然包含分发的名称,但情况并非总是如此。
根据所使用的Linux发行版,/etc
中的各种文件中可能会提供相关信息,包括但不限于:
/etc/os-release
/etc/debian_version
/etc/lsb-release
/etc/redhat-release