用PHP获取主机名的最佳方法 [英] Best way to get hostname with php
问题描述
我有一个安装在多台服务器和我们所有开发人员笔记本电脑上的php应用程序.我需要一种快速可靠的方法来获取服务器的主机名或其他一些唯一可靠的系统标识符.到目前为止,这是我们想到的:
I have a php application that is installed on several servers and all of our developers laptops. I need a fast and reliable way to get the server's hostname or some other unique and reliable system identifier. Here's what we have thought of so far:
<? $hostname = (!empty($_ENV["HOSTNAME"])) ? $_ENV["HOSTNAME"] : env('HOSTNAME'); ?>
<? $hostname = gethostbyaddr($_SERVER['SERVER_ADDR']); ?>
<? $hostname = exec('hostname'); ?>
您怎么看?
推荐答案
我想这可能不是一个选项,具体取决于您的环境.它是PHP 5.3中的新功能. php_uname('n')可以替代.
This might not be an option I suppose, depending on your environment. It's new in PHP 5.3. php_uname('n') might work as an alternative.
这篇关于用PHP获取主机名的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!