What does the output "Resource id #2" mean in PHP when using fsockopen?

The output "Resource id #2" in PHP when using fsockopen means that the function has successfully opened a socket connection, and the return value is a resource identifier for that connection. To use this resource to read or write data, you need to pass it to functions like fread() or fwrite().

$socket = fsockopen('example.com', 80, $errno, $errstr, 30);
if (!$socket) {
    echo "Error: $errstr ($errno)\n";
} else {
    fwrite($socket, "GET / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\n\r\n");
    while (!feof($socket)) {
        echo fgets($socket, 1024);
    }
    fclose($socket);
}