public static function getPort($start = 3000, $hostname = null, $end = null)
    {
        $end = $end ?: $start + 30;
        for ($port = $start; $port <= $end; $port++) {
            if (static::validatePort($port) && !static::isPortInUse($port, $hostname)) {
                return $port;
            }
        }
        throw new \Exception(sprintf('Failed to find an available port between %d and %d', $start, $end));
    }
public static function getPort($start = 3000, $hostname = null, $end = null)
    {
        $end = $end ?: $start + 30;
        for ($port = $start; $port <= $end; $port++) {
            if (static::validatePort($port) && !static::isPortInUse($port, $hostname)) {
                return $port;
            }
        }
        throw new \Exception(sprintf('Failed to find an available port between %d and %d', $start, $end));
    }
public static function getPort ( $ start = 3000 , $ hostname = null , $ end = null ) { $ end = $ end ? : $ start + 30 ; for ( $ port = $ start ; $ port <= $ end ; $ port ++ ) { if ( static :: validatePort ( $ port ) && ! static :: isPortInUse ( $ port , $ hostname ) ) { return $ port ; } } throw new \ Exception ( sprintf ( 'Failed to find an available port between %d and %d' , $ start , $ end ) ) ; }
Get the next available valid port.

@param int         $start    The starting port number.
@param string|null $hostname The hostname, defaults to 127.0.0.1.
@param int|null    $end      The maximum port number to try (defaults to
$start + 30);

@throws \Exception on failure

@return int
Get the next available valid port .