Can't read from socket (hangs)
Sockets in PHP, as in most programming languages, are opened in blocking mode by default, unless set otherwise using socket_set_nonblock
.
This means that unless a timeout/error occurs or data is received, socket_read
will hang there forever.
Since your termination character seems to be a new line, try that:
while($resp = socket_read($sock, 1000)) {
$str .= $resp;
if (strpos($str, "\n") !== false) break;
}
socket_close($sock);
die("Server said: $str");