function BuildTestBase::checkPortIsAvailable

Same name in other branches
  1. 9 core/tests/Drupal/BuildTests/Framework/BuildTestBase.php \Drupal\BuildTests\Framework\BuildTestBase::checkPortIsAvailable()
  2. 8.9.x core/tests/Drupal/BuildTests/Framework/BuildTestBase.php \Drupal\BuildTests\Framework\BuildTestBase::checkPortIsAvailable()
  3. 11.x core/tests/Drupal/BuildTests/Framework/BuildTestBase.php \Drupal\BuildTests\Framework\BuildTestBase::checkPortIsAvailable()

Checks whether a port is available.

Parameters

$port: A number between 1024 and 65536.

Return value

bool

3 calls to BuildTestBase::checkPortIsAvailable()
BuildTestBase::findAvailablePort in core/tests/Drupal/BuildTests/Framework/BuildTestBase.php
Discover an available port number.
BuildTestBase::instantiateServer in core/tests/Drupal/BuildTests/Framework/BuildTestBase.php
Do the work of making a server process.
BuildTestTest::testPortMany in core/tests/Drupal/BuildTests/Framework/Tests/BuildTestTest.php
@covers ::findAvailablePort

File

core/tests/Drupal/BuildTests/Framework/BuildTestBase.php, line 508

Class

BuildTestBase
Provides a workspace to test build processes.

Namespace

Drupal\BuildTests\Framework

Code

protected function checkPortIsAvailable($port) {
    $fp = @fsockopen(self::$hostName, $port, $errno, $errstr, 1);
    // If fsockopen() fails to connect, probably nothing is listening.
    // It could be a firewall but that's impossible to detect, so as a
    // best guess let's return it as available.
    if ($fp === FALSE) {
        return TRUE;
    }
    else {
        fclose($fp);
    }
    return FALSE;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.