What are the potential pitfalls of using fsocket for streaming data in PHP?

One potential pitfall of using fsocket for streaming data in PHP is that it can be prone to memory leaks if not properly managed. To avoid this issue, it is important to close the socket connection after streaming the data.

// Open socket connection
$socket = fsockopen('example.com', 80);

// Send data
fwrite($socket, $data);

// Receive response
$response = '';
while (!feof($socket)) {
    $response .= fgets($socket, 1024);
}

// Close socket connection
fclose($socket);