public static function isPortOpen($host, $port, $protocol)
    {
        $protocol = strtolower($protocol);
        
        if ($protocol != 'tcp' && $protocol != 'udp')
        {
            $errMsg = 'Unrecognized protocol [' . $protocol . '] ' . 
                      'please specify [tcp] or [udp]';
            throw new \Exception($errMsg);
        }
        
        if (empty($host))
        {
            $host = self::getPublicIp();
        }

        foreach ($ports as $port)
        {
            $connection = @fsockopen($host, $port);

            if (is_resource($connection))
            {
                $isOpen = true;
                fclose($connection);
            }

            else
            {
                $isOpen = false;
            }
        }
        
        return $isOpen;
    }
public static function isPortOpen($host, $port, $protocol)
    {
        $protocol = strtolower($protocol);
        
        if ($protocol != 'tcp' && $protocol != 'udp')
        {
            $errMsg = 'Unrecognized protocol [' . $protocol . '] ' . 
                      'please specify [tcp] or [udp]';
            throw new \Exception($errMsg);
        }
        
        if (empty($host))
        {
            $host = self::getPublicIp();
        }

        foreach ($ports as $port)
        {
            $connection = @fsockopen($host, $port);

            if (is_resource($connection))
            {
                $isOpen = true;
                fclose($connection);
            }

            else
            {
                $isOpen = false;
            }
        }
        
        return $isOpen;
    }
public static function isPortOpen ( $ host , $ port , $ protocol ) { $ protocol = strtolower ( $ protocol ) ; if ( $ protocol != 'tcp' && $ protocol != 'udp' ) { $ errMsg = 'Unrecognized protocol [' . $ protocol . '] ' . 'please specify [tcp] or [udp]' ; throw new \ Exception ( $ errMsg ) ; } if ( empty ( $ host ) ) { $ host = self :: getPublicIp ( ) ; } foreach ( $ ports as $ port ) { $ connection = @ fsockopen ( $ host , $ port ) ; if ( is_resource ( $ connection ) ) { $ isOpen = true ; fclose ( $ connection ) ; } else { $ isOpen = false ; } } return $ isOpen ; }
Checks to see if the specified port is open.
@param string $host - the host to check against.
@param int $port - the port to check
@return $isOpen - true if port is open, false if not.
Checks to see if the specified port is open .