/* Get the exact same packet again, but remove it from the buffer this time. */echo "Data: '" . stream_socket_recvfrom($socket, 1500) . "'\n";

/* Close it up */fclose($socket);fclose($server);?>

Notes

Note:

If a message received is longer than the length
parameter, excess bytes may be discarded depending on the type of socket
the message is received from (such as UDP).

Note:

Calls to stream_socket_recvfrom() on socket-based
streams, after calls to buffer-based stream functions (like
fread() or stream_get_line()) read
data directly from the socket and bypass the stream buffer.

User Contributed Notes 2 notes

Note that stream_socket_recvfrom() bypasses stream wrappers including TLS/SSL. While reading from an encrypted stream with fread() will return decrypted data, using stream_socket_recvfrom() will give you the original encrypted bytes.