PHP判断服务器端口是否打开的代码_PHP教程
程序员文章站
2024-01-30 22:08:58
...
记录一下,以后备用
- php
- $host = www.google.com; //要ping的地址,也可以是IP
- $port = 80; //要ping的端口
- $num = 3;
- function microtime_float()
- {
- list($usec, $sec) = explode(" ", microtime());
- return ((float)$usec + (float)$sec);
- }
- function ping($host,$port)
- {
- $time_start = microtime_float();
- $ip = gethostbyname($host);
- $fp = @fsockopen($host,$port,&$errno,&$errstr,1);
- if(!$fp) return replay time out!;
- $get = "GET / HTTP/1.1 Host:".$host." Connection: Close ";
- @fputs($fp,$get);
- @fclose($fp);
- $time_end = microtime_float();
- $time = $time_end - $time_start;
- $time = ceil($time * 1000);
- return Reply from .$ip.: time=.$time.msbr />;
- }
- echo Pinging .$host. [.gethostbyname($host).] with Port:.$port. of data:br />br />." ";
- for($i = 0;$i $num;$i++)
- {
- ping($host,$port);
- sleep(1);
- ob_flush();
- flush();
- }
- ?>
本文摘自 http://www.cnblogs.com/luoine/archive/2010/12/01/1893156.html
上一篇: Oracle查看角色与角色间权限的差异
下一篇: 几个扩展存储过程使用方法