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. 10 core/tests/Drupal/BuildTests/Framework/BuildTestBase.php \Drupal\BuildTests\Framework\BuildTestBase::checkPortIsAvailable()

Checks whether a port is available.

Parameters

int $port: A number between 1024 and 65536.

Return value

bool

4 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
TemplateProjectTestBase::instantiateServer in core/modules/package_manager/tests/src/Build/TemplateProjectTestBase.php
Do the work of making a server process.

File

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

Class

BuildTestBase
Provides a workspace to test build processes.

Namespace

Drupal\BuildTests\Framework

Code

protected function checkPortIsAvailable($port) : bool {
    $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.