有提供本地主机名的PHP函数或变量吗? [英] Is there a PHP function or variable giving the local host name?

查看:74
本文介绍了有提供本地主机名的PHP函数或变量吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当脚本在Apache下运行时,我将$_SERVER['SERVER_NAME']值插入错误报告电子邮件中.

When a script runs under Apache, I insert $_SERVER['SERVER_NAME'] value into an error reporting e-mail message.

但是,如果Web脚本用nohup php ...派生工作者"作业,则$_SERVER['SERVER_NAME']在那里似乎是空的.因此,如果发生错误,则报告时将不包含主机名.

However, if a Web script forks a "worker" job with nohup php ..., $_SERVER['SERVER_NAME'] appears to be empty there. Thus, if an error occurs, it's reported without a host name.

是否可以通过PHP可靠地获取主机名,而无需调用Unix hostname命令?

Can I reliably get the host name by means of PHP, without calling Unix hostname command?

推荐答案

php_uname("n")

(PHP 4> = 4.0.2,PHP 5)
php_uname-返回有关 操作系统PHP正在运行

(PHP 4 >= 4.0.2, PHP 5)
php_uname — Returns information about the operating system PHP is running on

php_uname()返回有关操作系统PHP的描述. 继续前进.这是您在顶部看到的相同字符串 phpinfo()输出.对于仅操作系统的名称,请考虑 使用PHP_OS常量,但请记住,此常量将包含 操作系统PHP建立在其上.

php_uname() returns a description of the operating system PHP is running on. This is the same string you see at the very top of the phpinfo() output. For the name of just the operating system, consider using the PHP_OS constant, but keep in mind this constant will contain the operating system PHP was built on.

在某些较旧的UNIX平台上,它可能无法确定 当前的操作系统信息,在这种情况下,它将恢复为显示 OS PHP建立在其上.只有在您的uname()库中才会发生这种情况 呼叫不存在或不起作用.

On some older UNIX platforms, it may not be able to determine the current OS information in which case it will revert to displaying the OS PHP was built on. This will only happen if your uname() library call either doesn't exist or doesn't work.

这篇关于有提供本地主机名的PHP函数或变量吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆