【发布时间】:2018-04-04 10:51:39
【问题描述】:
我正在使用 gethostbyname 函数来获取我们域名的 IP 地址。
当它在 apache 中运行并在命令行中使用 php 时,它需要 5.0695459842682 秒才能获得完整结果。
<?php
$domain_name = $argv[1];
$stime = microtime(true);
$ip =gethostbyname($domain_name);
$etime = microtime(true);
$ttime = $etime - $stime;
echo "Total time for gethostbyname : $ttime\n";
echo $ip."\n";
?>
当我通过传递 google.com 作为域在 php 命令行中运行脚本时,它返回以下结果。
gethostbyname 的总时间:5.0695459842682 216.58.203.142
谁能帮我出来把时间缩短到1秒以内。
问候, 维涅什库马尔 K
【问题讨论】:
-
会不会是你的网络很慢?
gethostbyname进行 nslookup。我将$argv[1]更改为example.org.(在某些服务器上需要尾随点)并获得0.000637s 的运行时间 -
这与代码无关。这称为延迟,在网络环境中习惯它。
标签: php server vps shared-hosting