PHP如何判断服务器端口是否成功开启?

2026-04-02 14:411阅读0评论SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计285个文字,预计阅读时间需要2分钟。

PHP如何判断服务器端口是否成功开启?

记录一+记录一下,备用:

bash$host='www.google.com';// 要ping的地址,也可以是IP$port='80';// 要ping的端口$num=3;function microtime_float(){ list($usec, $sec)=explode( , microtime()); return ((float)$usec + (float)$sec);}

记录一

记录一下,以后备用

  • $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,  
  • if(!$fp) return 'replay time out!';  
  • $get = "GET / HTTP/1.1/r/nHost:".$host."/r/nConnection: Close/r/n/r/n";  
  • @fputs($fp,$get);  
  • @fclose($fp);  
  • $time_end = microtime_float();  
  • $time = $time_end - $time_start;  
  • $time = ceil($time * 1000);  
  • return 'Reply from '.$ip.': time='.$time.'ms';  
  • }  
  • echo 'Pinging '.$host.' ['.gethostbyname($host).'] with Port:'.$port.' of data:'."/r/n";  
  • for($i = 0;$i < $num;$i++)  
  • {  
  • ping($host,$port);  
  • sleep(1);  
  • ob_flush();  
  • flush();  
  • }  
  • ?> 
  • 本文摘自 www.cnblogs.com/luoine/archive/2010/12/01/1893156.html

    PHP如何判断服务器端口是否成功开启?

    欢迎大家阅读《php判断服务器端口是否打开的代码_php》,跪求各位点评,若觉得好的话请收藏本文,by


    标签:代码PHP

    本文共计285个文字,预计阅读时间需要2分钟。

    PHP如何判断服务器端口是否成功开启?

    记录一+记录一下,备用:

    bash$host='www.google.com';// 要ping的地址,也可以是IP$port='80';// 要ping的端口$num=3;function microtime_float(){ list($usec, $sec)=explode( , microtime()); return ((float)$usec + (float)$sec);}

    记录一

    记录一下,以后备用

  • $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,  
  • if(!$fp) return 'replay time out!';  
  • $get = "GET / HTTP/1.1/r/nHost:".$host."/r/nConnection: Close/r/n/r/n";  
  • @fputs($fp,$get);  
  • @fclose($fp);  
  • $time_end = microtime_float();  
  • $time = $time_end - $time_start;  
  • $time = ceil($time * 1000);  
  • return 'Reply from '.$ip.': time='.$time.'ms';  
  • }  
  • echo 'Pinging '.$host.' ['.gethostbyname($host).'] with Port:'.$port.' of data:'."/r/n";  
  • for($i = 0;$i < $num;$i++)  
  • {  
  • ping($host,$port);  
  • sleep(1);  
  • ob_flush();  
  • flush();  
  • }  
  • ?> 
  • 本文摘自 www.cnblogs.com/luoine/archive/2010/12/01/1893156.html

    PHP如何判断服务器端口是否成功开启?

    欢迎大家阅读《php判断服务器端口是否打开的代码_php》,跪求各位点评,若觉得好的话请收藏本文,by


    标签:代码PHP