哈哈,用exec执行系统的PING命令再分析,如何呢?希望有更好的办法。陪LZ一起等

解决方案 »

  1.   

    在本站找到一个演示代码,思路和“乡约北京”一致,我贴在下面:<?php   
      $size=1024*50;//这里你可以放大到*足够大*以确保数据能尽可能的接近真实   
      $callnumber=3;   
      $ip=$_SERVER[REMOTE_ADDR];   
      list($useca,$seca)=explode("   ",microtime());   
      @exec("ping   -n   $callnumber   -l   $size   $ip",$data)   or   die("Support   Forbid!");   
      list($usecb,$secb)=explode("   ",microtime());   
      $sec=$secb-$seca;   
      $msg=$data[count($data)-3];   
      list($drop,$info)=explode("(",$msg);   
      list($info,$drop)=explode("%",$info);   
      $spead=($size*$callnumber-$size*$callnumber*$info/100)/$sec;   
      echo   sprintf("连接速度%.2f(k/s)",$spead/1024);   
      ?>  
    但是如果服务器不允许ping,是不是就不准确了?大家还有什么其他好的办法吗?
      

  2.   

    PHP只能运行在你的服务器上
    你服务器到别人网站的速度有什么用啊
      

  3.   

    BAIDU上的链接速度我只能靠服务器上的测试与别人的服务器响应来分析。
    EXEC('PING')
      

  4.   

    时时测试是不可能的。。
    划n个ip段,定时测试。也是一个解决方案。
      

  5.   

    看来实时是不可能了。那如果划N个ip段的话,一台服务器上看来无法完成了,必须得在所划的ip段中,有测试机才行了。
      

  6.   

    http://11.mydrivers.com/drivers/js/speed.js
      

  7.   

    用js测速
    ----------------------
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
     <HEAD>
      <TITLE> New Document </TITLE>
      <META NAME="Generator" CONTENT="EditPlus">
      <META NAME="Author" CONTENT="">
      <META NAME="Keywords" CONTENT="">
      <META NAME="Description" CONTENT="">
     </HEAD> <BODY>
      <script language=javascript>
    tim=1
    setInterval("tim++",100)
    b=1var autourl=new Array()
    autourl[1]="www.njcatv.net"
    autourl[2]="javacool.3322.net"
    autourl[3]="www.sina.com.cn"
    autourl[4]="www.tominfo9.com"
    autourl[5]="www.cctv.com"function butt(){
    document.write("<form name=autof>")
    for(var i=1;i<autourl.length;i++)
    document.write("<input type=text name=txt"+i+" size=10 value=测试中……> =》<input type=text name=url"+i+" size=40> =》<input type=button value=GO onclick=window.open(this.form.url"+i+".value)>");
    document.write("<input type=submit value=刷新></form>")
    }
    butt()
    function auto(url){
    document.forms[0]["url"+b].value=url
    if(tim>200)
    {document.forms[0]["txt"+b].value="链接超时"}
    else
    {document.forms[0]["txt"+b].value="时间"+tim/10+"秒"}
    b++
    }
    function run()

        for(var i=1;i<autourl.length;i++)
        document.write("<img src=http://"+autourl[i]+"/"+Math.random()+" width=1 height=1 onerror=auto('http://"+autourl[i]+"')>")}
    run()</script>
     </BODY>
    </HTML>
      

  8.   

    大家说一下,楼上说的是否为客户端到代码中列举的站点的链接速度?另外,如何把js中的得到的时间值传给php?
      

  9.   

    用js可以得到客户端到各站点的速度。
    这个速度直接显示出来就是了。为什么要传给php?想自动使用最快的,也可以js直接实现跳转。
      

  10.   

    hanpoyangtitan(韩波洋)的例子原理是对的。但应该使用ajax来测速。onerror并不能真实得到连接速度。比如这个网站根本不通,那么连接将立即返回得到最快速度。但正确的答案应该是超时。
      

  11.   

    那这个onerror这个地方应该如何解决?
      

  12.   

    现在的浏览器好像限制ajax访问当前域名之外的服务器的