用fsockopen函数
int fsockopen(string hostname, int port, int [errno], string [errstr], int [timeout]);
timeout 选项表示多久没有连上就中断
int fsockopen(string hostname, int port, int [errno], string [errstr], int [timeout]);
timeout 选项表示多久没有连上就中断
用XMLHTTP
检测某个网站的链接速度:
把如下代码加入<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.nuaa.edu.cn"
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)><br/>")
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>
但是对 socket库 里的函数无效,只适用 file 系列函数
我试过,好像只是一个打开网页而已啊。
最简单的:ini_set("default_socket_timeout","1");
你说的ini_set这个函数怎么用啊??
谢谢你,用你的这个已经实现成功,但还有一个问题,我的那些网址前面都有“http://”,怎么样用正则函数来取后面的地址呢,如果不是正则函数又怎么样取呢?
不是有现成的函数吗?parse_url
剖析 URL 字串。语法: array parse_url(string url);传回值: 阵列函式种类: 资料处理
内容说明 本函式将 URL 字串予以剖析,并将结果传回阵列中。完整的 URL 类似这样子scheme://user:pass@host:port/path?query。如 http://john:[email protected]:88/abcdef.php?a=1234因此传回的阵列包括了下列元素:scheme、host、port、user、pass、path、query 与 fragment 等。