What is the purpose of the port parameter in the fsockopen function call?

The purpose of the port parameter in the fsockopen function call is to specify the port number on the remote server that the connection should be established with. This is necessary because different services on a server listen on different port numbers, and specifying the correct port is essential for establishing a successful connection.

$host = 'example.com';
$port = 80; // Specify the port number here
$timeout = 30; // Set a timeout value

$socket = fsockopen($host, $port, $errno, $errstr, $timeout);

if (!$socket) {
    echo "Error: $errstr ($errno)";
} else {
    // Connection successful, do something with the socket
    fclose($socket);
}