logger = $logger; } /** * @param string $url * @param integer $port * @return bool */ public function canConnect(string $url, int $port): bool { $this->logger->debug("attempting to connect to <$url> on port <$port>"); $fp = @fsockopen($url, $port, $error, $errorstr, self::CONNECTION_TIMEOUT); if (is_resource($fp)) { fclose($fp); $this->logger->debug("connection to <$url> on port <$port> established"); return true; } $this->logger->debug("cannot connect to <$url> on port <$port>"); return false; } }