栏目导航
热点推荐
- 开发者必备,超实用的PHP代码片
- 提高PHP编程效率的53种方法
- PHP精华的代码收藏
- PHP.ini配置文件(中文)
- PHP如何防止注入及开发安全
- 提高PHP编程效率的53个要点
- 实际开发中可能用到的PHP的字符
- PHP无限分类的原理
- PHP验证码类代码( 最新修改,完全
- PHP判断端口是否打开的代码
- PHP网站转移实战经验之谈
- phpMyAdmin配置文件说明
阅览排行
PHP判断端口是否打开的代码
www.jz123.cn 2010-12-03 来源: 站长家园 责任编辑(袁袁) 我要投递新闻
1 <?php
2 $host = 'www.baidu.com'; //要ping的地址,也可以是IP
3 $port = '80'; //要ping的端口
4 $num = 3;
5 function microtime_float()
6 {
7 list($usec, $sec) = explode(" ", microtime());
8 return ((float)$usec + (float)$sec);
9 }
10 function ping($host,$port)
11 {
12 $time_start = microtime_float();
13 $ip = gethostbyname($host);
14 $fp = @fsockopen($host,$port,&$errno,&$errstr,1);
15 if(!$fp) return 'replay time out!';
16 $get = "GET / HTTP/1.1\r\nHost:".$host."\r\nConnection: Close\r\n\r\n";
17 @fputs($fp,$get);
18 @fclose($fp);
19 $time_end = microtime_float();
20 $time = $time_end - $time_start;
21 $time = ceil($time * 1000);
22 return 'Reply from '.$ip.': time='.$time.'ms<br />';
23 }
24 echo 'Pinging '.$host.' ['.gethostbyname($host).'] with Port:'.$port.' of data:<br /><br />'."\r\n";
25 for($i = 0;$i < $num;$i++)
26 {
27 ping($host,$port);
28 sleep(1);
29 ob_flush();
30 flush();
31 }
32 ?>
33
2 $host = 'www.baidu.com'; //要ping的地址,也可以是IP
3 $port = '80'; //要ping的端口
4 $num = 3;
5 function microtime_float()
6 {
7 list($usec, $sec) = explode(" ", microtime());
8 return ((float)$usec + (float)$sec);
9 }
10 function ping($host,$port)
11 {
12 $time_start = microtime_float();
13 $ip = gethostbyname($host);
14 $fp = @fsockopen($host,$port,&$errno,&$errstr,1);
15 if(!$fp) return 'replay time out!';
16 $get = "GET / HTTP/1.1\r\nHost:".$host."\r\nConnection: Close\r\n\r\n";
17 @fputs($fp,$get);
18 @fclose($fp);
19 $time_end = microtime_float();
20 $time = $time_end - $time_start;
21 $time = ceil($time * 1000);
22 return 'Reply from '.$ip.': time='.$time.'ms<br />';
23 }
24 echo 'Pinging '.$host.' ['.gethostbyname($host).'] with Port:'.$port.' of data:<br /><br />'."\r\n";
25 for($i = 0;$i < $num;$i++)
26 {
27 ping($host,$port);
28 sleep(1);
29 ob_flush();
30 flush();
31 }
32 ?>
33
2
上一篇:PHP上传文件类型彻底判断方案及PHP+nginx上传大小彻底控制方案 下一篇:PHP声明变量