From f144fb23139c6c9f63294b71bc8bc2f5fec5ba4e Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Thu, 9 Oct 2025 17:04:13 +0300 Subject: [PATCH] Test http servers --- .../src/Model/Table/HttpServersTable.php | 44 +++++++++++++++++++ .../src/Model/Table/SqlServersTable.php | 2 - 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/app/plugins/CoreServer/src/Model/Table/HttpServersTable.php b/app/plugins/CoreServer/src/Model/Table/HttpServersTable.php index 6eeff5cd7..5bd3c3aad 100644 --- a/app/plugins/CoreServer/src/Model/Table/HttpServersTable.php +++ b/app/plugins/CoreServer/src/Model/Table/HttpServersTable.php @@ -176,4 +176,48 @@ public function validationDefault(Validator $validator): Validator { return $validator; } + + + /** + * Test TCP connectivity to the HTTP server. + * + * @param int $serverId ID of the HTTP server configuration + * @param string $name Name of the connection test (for logging) + * @return bool True if connection succeeds, false otherwise + * @since COmanage Registry v5.2.0 + */ + public function connect(int $serverId, string $name): bool + { + try { + // Fetch the configured HTTP server + $httpServer = $this->get($serverId); + + // Parse URL to extract host and port + $parts = parse_url((string)$httpServer->url); + if ($parts === false || empty($parts['host'])) { + return false; + } + + $host = $parts['host']; + $scheme = $parts['scheme'] ?? 'http'; + $port = isset($parts['port']) + ? (int)$parts['port'] + : ($scheme === 'https' ? 443 : 80); + + // Attempt a TCP connection as a liveness check + $timeout = 5.0; // seconds + $errno = 0; + $errstr = ''; + $conn = @fsockopen($host, $port, $errno, $errstr, $timeout); + + if (is_resource($conn)) { + fclose($conn); + return true; + } + + return false; + } catch (\Throwable $e) { + return false; + } + } } diff --git a/app/plugins/CoreServer/src/Model/Table/SqlServersTable.php b/app/plugins/CoreServer/src/Model/Table/SqlServersTable.php index d84242fb2..079b67bb2 100644 --- a/app/plugins/CoreServer/src/Model/Table/SqlServersTable.php +++ b/app/plugins/CoreServer/src/Model/Table/SqlServersTable.php @@ -203,8 +203,6 @@ public function pingDb(string $name = 'my_temp_connection'): bool { try { $conn = ConnectionManager::get($name); - // Force immediate connection attempt - $conn->connect(); // Use an engine-appropriate lightweight query $sql = ($conn->getDriver() instanceof \Portal89\OracleDriver\Database\Driver\OracleOCI)