private function isPortAvailable(int $port) : bool
{
$h = null;
try {
$h = socket_create_listen($port);
if ($h !== false) {
return true;
}
} catch (\ErrorException $e) {
// just ignore exception port already in use
} finally {
if (is_resource($h)) {
socket_close($h);
}
}
return false;
}