百科狗-知识改变命运!
--

php_uname() - php 选项信息函数

梵高1年前 (2023-11-21)阅读数 24#技术干货
文章标签常量

php_uname()

(PHP 4 >= 4.0.2, PHP 5, PHP 7)

返回运行 PHP 的系统的有关信息

说明

php_uname([string $mode="a"]): string

php_uname() - php 选项信息函数

php_uname()返回了运行 PHP 的操作系统的描述。这和phpinfo()最顶端上输出的是同一个字符串。如果仅仅要获取操作系统的名称。可以考虑使用常量PHP_OS,不过要注意该常量会包含 PHP 构建(built)时的操作系统名。

在一些旧的 UNIX 平台,它有可能无法检测到当前系统的信息,然后会还原显示成构建 PHP 时的系统信息。这仅仅在你的 uname()函数库不存在或无法运行时发生。

参数

$mode

$mode是单个字符,用于定义要返回什么信息:

  • 'a':此为默认。包含序列"s n r v m"里的所有模式。
  • 's':操作系统名称。例如:FreeBSD
  • 'n':主机名。例如:localhost.example.com
  • 'r':版本名称,例如:5.1.2-RELEASE
  • 'v':版本信息。操作系统之间有很大的不同。
  • 'm':机器类型。例如:i386

返回值

返回描述字符串。

范例

一些php_uname()的例子

同样可以方便地使用一些相关的PHP 预定义常量,例如:

一些系统相关常量的例子

参见

  • phpversion() 获取当前的PHP版本
  • php_sapi_name() 返回 web 服务器和 PHP 之间的接口类型
  • phpinfo() 输出关于 PHP 配置的信息
Note that PHP won't tell you that it reverted to displaying platform it was built on.
Note that php_uname('n') does not always equal $_SERVER['HOST_NAME']
The machine that you are running the script may server many different host names so don't use this when building urls.
Although it does not indicate receiving parameters this function allows some chars as parameters, they are the options a; m; n; r; s; v.
I don't know exactly what each one does, but below is a code example and its output on PHP 5.5 running on RedHat 4.4

Note that I used file_get_contentes with a file, that file is present in most linux boxies and varies on content, but most of times it indicates kernel version, linux version, distribution and so on. In my case my user didn't have access to the file, so to identify that it was a red hat I paid attention to php_info outputs, there in the middle was the postgress driver description, p. eg indicating the distribution.
I guess there is no easy way to find out the server version programmatically a 100% of times, but by and large you can get around by yourself.

鹏仔微信 15129739599 鹏仔QQ344225443 鹏仔前端 pjxi.com 共享博客 sharedbk.com

免责声明:我们致力于保护作者版权,注重分享,当前被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理!邮箱:344225443@qq.com)

图片声明:本站部分配图来自网络。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!

内容声明:本文中引用的各种信息及资料(包括但不限于文字、数据、图表及超链接等)均来源于该信息及资料的相关主体(包括但不限于公司、媒体、协会等机构)的官方网站或公开发表的信息。部分内容参考包括:(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供参考使用,不准确地方联系删除处理!本站为非盈利性质站点,本着为中国教育事业出一份力,发布内容不收取任何费用也不接任何广告!)