Skip to content

Commit

Permalink
Test http servers
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis committed Oct 17, 2025
1 parent 37a12dd commit 390c5ad
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
44 changes: 44 additions & 0 deletions app/plugins/CoreServer/src/Model/Table/HttpServersTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
2 changes: 0 additions & 2 deletions app/plugins/CoreServer/src/Model/Table/SqlServersTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 390c5ad

Please sign in to comment.