What are the differences between Query Port and Connect Port in PHP server scripts, and how do they impact server status checks?

When conducting server status checks in PHP server scripts, it is important to understand the differences between the Query Port and Connect Port. The Query Port is typically used for querying server information and retrieving data, while the Connect Port is used for establishing a connection to the server. It is crucial to use the correct port depending on the purpose of the server status check to ensure accurate results.

// Example of using Query Port for server status check
$serverAddress = '127.0.0.1';
$serverQueryPort = 27015;

$socket = @fsockopen('udp://' . $serverAddress, $serverQueryPort, $errno, $errstr, 1);
if ($socket !== false) {
    // Server is reachable via Query Port
    fclose($socket);
    echo 'Server is online';
} else {
    echo 'Server is offline';
}