/** * 檢測端口是否開放 * @param $ip * @param $port * @return string */ public function checkPort($ip,$port) { $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); socket_set_nonblock($sock); socket_connect($sock,$ip, $port); socket_set_block($sock); $return = @socket_select($r = array($sock), $w = array($sock), $f = array($sock), 3); socket_close($sock); switch($return) { case 2: echo "$ip:$port 關閉\n"; break; case 1: echo "$ip:$port 打開\n"; break; case 0: echo "$ip:$port 超時\n"; break; } }