Why does the get_resource_type() function return "stream" instead of "socket" when using fsockopen() in PHP?

The get_resource_type() function returns "stream" instead of "socket" when using fsockopen() in PHP because fsockopen() creates a stream resource, not a socket resource. To correctly identify the resource type as a socket, you can use the stream_socket_get_name() function to get the socket name.

$socket = fsockopen('example.com', 80, $errno, $errstr, 30);
$socketName = stream_socket_get_name($socket, true);
echo "Resource type: " . get_resource_type($socket) . "\n";
echo "Socket name: " . $socketName . "\n";