我需要的是一个php函数来检索与hostname -f执行相同的内容:
$ hostname -f #returns needed: system01.dev.lan
我尝试了以下方法:
php_uname('n') // returns: system01
gethostname() // returns: system01
gethostbyname(gethostname()) // returns ip address
gethostbyname(gethostname() . '.') // returns system01
$_SERVER不存在(因为只有CLI环境)
再次强调,我知道我可以做到这一点
php -r "var_dump(shell_exec('hostname -f'));"
但对于这个微不足道的任务,我认为php应该有内置功能来检索fqdn。
gethostbyaddr('127.0.0.1')
和hostname -f
之间的区别。我已经相应地更新了帖子,在末尾添加了两段内容。 - lxg