��ǰλ�ã�首页 > 集团介绍

集团介绍

主题:PHP页面编程:判断服务器某个端口是否打开的代码

����:ʱ��:2019-04-13
主题:PHP页面编程:判断服务器某个端口是否打开的代码下内容为程序代码: 1 1 <?php 2 2 $host = 'www.baidu.com'; //要ping的地址,也可以是IP 3 3 $port = '80'; //要ping的端口 4 4 $num = 3; 5 5 function microtime_float() 6 6 { 7 7 list($usec, $sec) = explode(" ", microtime()); 8 8 return ((float)$usec + (float)$sec); 9 9 } 10 10 function ping($host,$port) 11 11 { 12 12 $time_start = microtime_float(); 13 13 $ip = gethostbyname($host); 14 14 $fp = @fsockopen($host,$port,&$errno,&$errstr,1); 15 15 if(!$fp) return 'replay time out!'; 16 16 $get = "GET / HTTP/1.1\r\nHost:".$host."\r\nConnection: Close\r\n\r\n"; 17 17 @fputs($fp,$get); 18 18 @fclose($fp); 19 19 $time_end = microtime_float(); 20 20 $time = $time_end - $time_start; 21 21 $time = ceil($time * 1000); 22 22 return 'Reply from '.$ip.': time='.$time.'ms<br />'; 23 23 } 24 24 echo 'Pinging '.$host.' ['.gethostbyname($host).'] with Port:'.$port.' of data:<br /><br />'."\r\n"; 25 25 for($i = 0;$i < $num;$i++) 26 26 { 27 27 ping($host,$port); 28 28 sleep(1); 29 29 ob_flush(); 30 30 flush(); 31 31 } 32 32 ?> 33 33 34  
���ű�ǩ: