从浏览器而不是服务器测量 Ping 时间?

发布于 2024-10-20 10:14:15 字数 1047 浏览 3 评论 0原文

我如何测量从用户浏览器到 IP 地址的 ping 时间,而不是从服务器到 IP 地址的 ping 时间。我希望能够在网站上获取并显示 ping 时间,该网站显示从该人的浏览器到 IP 地址的 ping 时间。

我见过的所有代码都可以 ping 通,但如果我没记错的话,它显示的是从服务器到 IP 地址的时间,而不是从客户端浏览器或 PC 到 IP 地址的时间。

我也尝试过在 PHP 中加载图像并测量加载所需的时间(我认为!),这可能是一个选项,但我不知道在哪里测量时间。在服务器上还是在浏览器上?

<html>
<head>
<title>Psedo Ping Test</title>
</head>

<body>

<?php
$link2 = "http://www.is.co.za/Style%20Library/en-is/Themable/Images/ISlogo.jpg";
echo fopenTest($link2)
?>

</body>
</html>

<?php

function fopenTest($link) {

  if(substr($link,0,4)!="http"){ 
    $link = "http://".$link;
  }

  $timestart = microtime();

  $churl = @fopen($link,'r');

  $timeend = microtime();
  $diff = number_format(((substr($timeend,0,9)) + (substr($timeend,-10)) -    (substr($timestart,0,9)) - (substr($timestart,-10))),4);
      $diff = $diff*100;

  if (!$churl) {
    $message="Offline";
  } else {
    $message="Online. Time : ".$diff."ms ";
  }

  fclose($churl); 

return  $message;
}

?>

How would I measure a ping time from the users browser to an IP address and not from the server to th IP address. I want to be able to get and show the ping times on a website that shows the ping times from that persons browser to an IP address.

All the code I've seen can ping, but if I'm not mistaken, it shows the time from the server to the IP address and not from the clients browser or PC to the IP address.

I've tried also loading an image in PHP and measuring the time it takes to load (I think!) and this might be an option but I don't know where the time is being measured. On the server or on the browser?

<html>
<head>
<title>Psedo Ping Test</title>
</head>

<body>

<?php
$link2 = "http://www.is.co.za/Style%20Library/en-is/Themable/Images/ISlogo.jpg";
echo fopenTest($link2)
?>

</body>
</html>

<?php

function fopenTest($link) {

  if(substr($link,0,4)!="http"){ 
    $link = "http://".$link;
  }

  $timestart = microtime();

  $churl = @fopen($link,'r');

  $timeend = microtime();
  $diff = number_format(((substr($timeend,0,9)) + (substr($timeend,-10)) -    (substr($timestart,0,9)) - (substr($timestart,-10))),4);
      $diff = $diff*100;

  if (!$churl) {
    $message="Offline";
  } else {
    $message="Online. Time : ".$diff."ms ";
  }

  fclose($churl); 

return  $message;
}

?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

べ映画 2024-10-27 10:14:15

看看这个。它主要与您的 PHP 示例相同。但用 JavaScript 完成。

Take look at this. It's mainly the same as your PHP example. But done in Javascript.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文